Class: Gem::Resolver::APISet
Relationships & Source Files | |
Namespace Children | |
Classes:
| |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
Set
|
|
Instance Chain:
self,
Set
|
|
Inherits: |
Gem::Resolver::Set
|
Defined in: | lib/rubygems/resolver/api_set.rb |
Overview
The global rubygems pool, available via the rubygems.org API. Returns instances of APISpecification
.
Class Method Summary
-
.new(dep_uri = "https://index.rubygems.org/info/") ⇒ APISet
constructor
Creates a new
APISet
that will retrieve gems from #uri using the RubyGems API URL #dep_uri which is described at guides.rubygems.org/rubygems-org-api.
Set
- Inherited
Instance Attribute Summary
-
#source
readonly
The
::Gem::Source
that gems are fetched from. -
#uri
readonly
The corresponding place to fetch gems.
-
#dep_uri
readonly
Internal use only
The URI for the dependency API this
APISet
uses.
Set
- Inherited
#errors | Errors encountered when resolving gems. |
#prerelease | When true, allows matching of requests to prerelease gems. |
#remote |
|
#remote? | When true, this set is allowed to access the network when looking up specifications or dependencies. |
Instance Method Summary
-
#find_all(req)
Return an array of
APISpecification
objects matchingDependencyRequest
req
. -
#prefetch(reqs)
A hint run by the resolver to allow the
Set
to fetch data for DependencyRequestsreqs
. - #lines(str) private
- #parse_gem(string) private
- #prefetch_now Internal use only
- #pretty_print(q) Internal use only
-
#versions(name)
Internal use only
Return data for all versions of the gem
name
.
Set
- Inherited
Constructor Details
.new(dep_uri = "https://index.rubygems.org/info/") ⇒ APISet
Creates a new APISet
that will retrieve gems from #uri using the RubyGems API URL #dep_uri which is described at guides.rubygems.org/rubygems-org-api
Instance Attribute Details
#dep_uri (readonly)
The URI for the dependency API this APISet
uses.
# File 'lib/rubygems/resolver/api_set.rb', line 13
attr_reader :dep_uri # :nodoc:
#source (readonly)
The ::Gem::Source
that gems are fetched from
# File 'lib/rubygems/resolver/api_set.rb', line 18
attr_reader :source
#uri (readonly)
The corresponding place to fetch gems.
# File 'lib/rubygems/resolver/api_set.rb', line 23
attr_reader :uri
Instance Method Details
#find_all(req)
Return an array of APISpecification
objects matching DependencyRequest
req
.
# File 'lib/rubygems/resolver/api_set.rb', line 48
def find_all(req) res = [] return res unless @remote if @to_fetch.include?(req.name) prefetch_now end versions(req.name).each do |ver| if req.dependency.match? req.name, ver[:number], @prerelease res << Gem::Resolver::APISpecification.new(self, ver) end end res end
#lines(str) (private)
[ GitHub ]# File 'lib/rubygems/resolver/api_set.rb', line 123
def lines(str) lines = str.split("\n") header = lines.index("---") header ? lines[header + 1..-1] : lines end
#parse_gem(string) (private)
[ GitHub ]#prefetch(reqs)
A hint run by the resolver to allow the Set
to fetch data for DependencyRequests reqs
.
# File 'lib/rubygems/resolver/api_set.rb', line 70
def prefetch(reqs) return unless @remote names = reqs.map {|r| r.dependency.name } needed = names - @data.keys - @to_fetch @to_fetch += needed end
#prefetch_now
# File 'lib/rubygems/resolver/api_set.rb', line 78
def prefetch_now # :nodoc: needed, @to_fetch = @to_fetch, [] needed.sort.each do |name| versions(name) end end
#pretty_print(q)
# File 'lib/rubygems/resolver/api_set.rb', line 86
def pretty_print(q) # :nodoc: q.group 2, "[APISet", "]" do q.breakable q.text "URI: #{@dep_uri}" q.breakable q.text "gem names:" q.pp @data.keys end end
#versions(name)
Return data for all versions of the gem name
.
# File 'lib/rubygems/resolver/api_set.rb', line 100
def versions(name) # :nodoc: if @data.key?(name) return @data[name] end uri = @dep_uri + name str = Gem::RemoteFetcher.fetcher.fetch_path uri lines(str).each do |ver| number, platform, dependencies, requirements = parse_gem(ver) platform ||= "ruby" dependencies = dependencies.map {|dep_name, reqs| [dep_name, reqs.join(", ")] } requirements = requirements.map {|req_name, reqs| [req_name.to_sym, reqs] }.to_h @data[name] << { name: name, number: number, platform: platform, dependencies: dependencies, requirements: requirements } end @data[name] end