In Files

  • rubygems/resolver/api_set.rb

Class/Module Index [+]

Quicksearch

Gem::Resolver::APISet

The global rubygems pool, available via the rubygems.org API. Returns instances of APISpecification.

Attributes

source[R]

The Gem::Source that gems are fetched from

uri[R]

The corresponding place to fetch gems.

Public Class Methods

new(dep_uri = 'https://rubygems.org/api/v1/dependencies') click to toggle source

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

 
               # File rubygems/resolver/api_set.rb, line 27
def initialize dep_uri = 'https://rubygems.org/api/v1/dependencies'
  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
end
            

Public Instance Methods

find_all(req) click to toggle source

Return an array of APISpecification objects matching DependencyRequest req.

 
               # File rubygems/resolver/api_set.rb, line 41
def find_all req
  res = []

  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) click to toggle source

A hint run by the resolver to allow the Set to fetch data for DependencyRequests reqs.

 
               # File rubygems/resolver/api_set.rb, line 57
def prefetch reqs
  names = reqs.map { |r| r.dependency.name }
  needed = names - @data.keys

  return if needed.empty?

  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
            

Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.

If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.

If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.

If you want to help improve the Ruby documentation, please visit Documenting-ruby.org.

blog comments powered by Disqus