123456789_123456789_123456789_123456789_123456789_

Class: Gem::Resolver::APISet

Relationships & Source Files
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

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

Set to true to disable network access for this set.

#remote?

When true, this set is allowed to access the network when looking up specifications or dependencies.

Instance Method Summary

Set - Inherited

#find_all

The find_all method must be implemented.

#prefetch

The #prefetch method may be overridden, but this is not necessary.

Constructor Details

.new(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

[ GitHub ]

  
# File 'lib/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

Instance Attribute Details

#dep_uri (readonly)

This method is for internal use only.

The URI for the dependency API this APISet uses.

[ GitHub ]

  
# File 'lib/rubygems/resolver/api_set.rb', line 11

attr_reader :dep_uri # :nodoc:

#source (readonly)

The ::Gem::Source that gems are fetched from

[ GitHub ]

  
# File 'lib/rubygems/resolver/api_set.rb', line 16

attr_reader :source

#uri (readonly)

The corresponding place to fetch gems.

[ GitHub ]

  
# File 'lib/rubygems/resolver/api_set.rb', line 21

attr_reader :uri

Instance Method Details

#find_all(req)

Return an array of APISpecification objects matching DependencyRequest req.

[ GitHub ]

  
# File 'lib/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.

[ GitHub ]

  
# File 'lib/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

#prefetch_now

This method is for internal use only.
[ GitHub ]

  
# File 'lib/rubygems/resolver/api_set.rb', line 76

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)

This method is for internal use only.
[ GitHub ]

  
# File 'lib/rubygems/resolver/api_set.rb', line 96

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)

This method is for internal use only.

Return data for all versions of the gem name.

[ GitHub ]

  
# File 'lib/rubygems/resolver/api_set.rb', line 110

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