Class: Gem::Resolver::APISet (Ruby 2.3.4)

In Files

  • rubygems/resolver/api_set.rb

Class/Module Index [+]

Quicksearch

Gem::Resolver::APISet

frozen_string_literal: true

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')

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 28
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
            

Public Instance Methods

find_all(req)

Return an array of APISpecification objects matching DependencyRequest req.

 
               # File rubygems/resolver/api_set.rb, line 46
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)

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

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

  @to_fetch += needed
end