PHP 8.2.31
Preview: api_set.rb Size: 2.27 KB
//proc/thread-self/root/opt/alt/ruby21/lib64/ruby/2.1.0/rubygems/resolver/api_set.rb

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

class Gem::Resolver::APISet < Gem::Resolver::Set

  ##
  # The URI for the dependency API this APISet uses.

  attr_reader :dep_uri # :nodoc:

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

  attr_reader :source

  ##
  # The corresponding place to fetch gems.

  attr_reader :uri

  ##
  # Creates a new APISet that will retrieve gems from +uri+ using the RubyGems
  # API URL +dep_uri+ which is described at
  # http://guides.rubygems.org/rubygems-org-api

  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
  end

  ##
  # Return an array of APISpecification objects matching
  # DependencyRequest +req+.

  def find_all req
    res = []

    return res unless @remote

    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

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

  def prefetch reqs
    return unless @remote
    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

  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

  ##
  # Return data for all versions of the gem +name+.

  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

end

Directory Contents

Dirs: 0 × Files: 24

Name Size Perms Modified Actions
3.26 KB lrw-r--r-- 2013-11-25 19:14:49
Edit Download
2.27 KB lrw-r--r-- 2014-02-06 02:59:36
Edit Download
1.74 KB lrw-r--r-- 2013-11-25 19:14:49
Edit Download
912 B lrw-r--r-- 2014-02-06 02:59:36
Edit Download
879 B lrw-r--r-- 2014-02-06 02:59:36
Edit Download
2.57 KB lrw-r--r-- 2013-11-25 19:14:49
Edit Download
252 B lrw-r--r-- 2013-11-19 00:34:13
Edit Download
1.77 KB lrw-r--r-- 2013-11-25 19:14:49
Edit Download
2.86 KB lrw-r--r-- 2014-02-06 02:59:36
Edit Download
837 B lrw-r--r-- 2013-11-25 19:14:49
Edit Download
1.36 KB lrw-r--r-- 2014-02-06 02:59:36
Edit Download
1.45 KB lrw-r--r-- 2013-11-19 00:34:13
Edit Download
862 B lrw-r--r-- 2013-11-25 19:14:49
Edit Download
3.00 KB lrw-r--r-- 2014-02-06 02:59:36
Edit Download
342 B lrw-r--r-- 2013-11-25 19:14:49
Edit Download
1.63 KB lrw-r--r-- 2014-02-06 02:59:36
Edit Download
1.18 KB lrw-r--r-- 2013-12-08 01:22:39
Edit Download
1.31 KB lrw-r--r-- 2013-12-08 01:22:39
Edit Download
1002 B lrw-r--r-- 2014-02-06 02:59:36
Edit Download
1.76 KB lrw-r--r-- 2013-11-25 19:14:49
Edit Download
1.06 KB lrw-r--r-- 2013-11-19 00:34:13
Edit Download
920 B lrw-r--r-- 2013-12-08 01:22:39
Edit Download
1.88 KB lrw-r--r-- 2014-02-06 02:59:36
Edit Download
545 B lrw-r--r-- 2013-11-25 19:14:49
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).