Class: Gem::Resolver::APISet
- Defined in:
- lib/rubygems/resolver/api_set.rb
Overview
The global rubygems pool, available via the rubygems.org API. Returns instances of APISpecification.
Instance Attribute Summary collapse
-
#dep_uri ⇒ Object
readonly
The URI for the dependency API this APISet uses.
-
#source ⇒ Object
readonly
The Gem::Source that gems are fetched from.
-
#uri ⇒ Object
readonly
The corresponding place to fetch gems.
Attributes inherited from Set
Instance Method Summary collapse
-
#find_all(req) ⇒ Object
Return an array of APISpecification objects matching DependencyRequest
req
. -
#initialize(dep_uri = 'https://rubygems.org/api/v1/dependencies') ⇒ APISet
constructor
Creates a new APISet that will retrieve gems from
uri
using the RubyGems API URLdep_uri
which is described at guides.rubygems.org/rubygems-org-api. -
#prefetch(reqs) ⇒ Object
A hint run by the resolver to allow the Set to fetch data for DependencyRequests
reqs
. -
#prefetch_now ⇒ Object
:nodoc:.
-
#pretty_print(q) ⇒ Object
:nodoc:.
-
#versions(name) ⇒ Object
Return data for all versions of the gem
name
.
Methods inherited from Set
Constructor Details
#initialize(dep_uri = 'https://rubygems.org/api/v1/dependencies') ⇒ 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
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rubygems/resolver/api_set.rb', line 27 def initialize dep_uri = 'https://rubygems.org/api/v1/dependencies' super() dep_uri = URI dep_uri unless URI === dep_uri # for ruby 1.8 @dep_uri = dep_uri @uri = dep_uri + '../..' @data = Hash.new { |h,k| h[k] = [] } @source = Gem::Source.new @uri @to_fetch = [] end |
Instance Attribute Details
#dep_uri ⇒ Object (readonly)
The URI for the dependency API this APISet uses.
10 11 12 |
# File 'lib/rubygems/resolver/api_set.rb', line 10 def dep_uri @dep_uri end |
#source ⇒ Object (readonly)
The Gem::Source that gems are fetched from
15 16 17 |
# File 'lib/rubygems/resolver/api_set.rb', line 15 def source @source end |
#uri ⇒ Object (readonly)
The corresponding place to fetch gems.
20 21 22 |
# File 'lib/rubygems/resolver/api_set.rb', line 20 def uri @uri end |
Instance Method Details
#find_all(req) ⇒ Object
Return an array of APISpecification objects matching DependencyRequest req
.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/rubygems/resolver/api_set.rb', line 45 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] res << Gem::Resolver::APISpecification.new(self, ver) end end res end |
#prefetch(reqs) ⇒ Object
A hint run by the resolver to allow the Set to fetch data for DependencyRequests reqs
.
67 68 69 70 71 72 73 |
# File 'lib/rubygems/resolver/api_set.rb', line 67 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 ⇒ Object
:nodoc:
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/rubygems/resolver/api_set.rb', line 75 def prefetch_now # :nodoc: needed, @to_fetch = @to_fetch, [] uri = @dep_uri + "?gems=#{needed.sort.join ','}" str = Gem::RemoteFetcher.fetcher.fetch_path uri loaded = [] Marshal.load(str).each do |ver| name = ver[:name] @data[name] << ver loaded << name end (needed - loaded).each do |missing| @data[missing] = [] end end |
#pretty_print(q) ⇒ Object
:nodoc:
95 96 97 98 99 100 101 102 103 104 |
# File 'lib/rubygems/resolver/api_set.rb', line 95 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) ⇒ Object
Return data for all versions of the gem name
.
109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/rubygems/resolver/api_set.rb', line 109 def versions name # :nodoc: if @data.key?(name) return @data[name] end uri = @dep_uri + "?gems=#{name}" str = Gem::RemoteFetcher.fetcher.fetch_path uri Marshal.load(str).each do |ver| @data[ver[:name]] << ver end @data[name] end |