class Gem::CompactIndexClient
The CompactIndexClient fetches and parses the compact index files (names, versions and info/[gem]) served by a gem server, keeping a local cache so subsequent fetches only transfer what changed.
This is an independent RubyGems port of Bundler::CompactIndexClient. Both implementations are intentionally kept separate so that changes on either side cannot affect the other; this one only depends on RubyGems itself.
Constants
Public Class Methods
Source
# File lib/rubygems/compact_index_client.rb, line 24 def self.debug return unless ENV["DEBUG_COMPACT_INDEX"] DEBUG_MUTEX.synchronize { warn("[#{self}] #{yield}") } end
Source
# File lib/rubygems/compact_index_client.rb, line 42 def initialize(directory, fetcher = nil) @cache = Cache.new(directory, fetcher) @parser = Parser.new(@cache) end
The client is instantiated with:
-
directory: the root directory where the cache files are stored. -
fetcher: (optional) an object that responds to #call(uri_path, headers) and returns a Gem::Net::HTTP response. When the fetcher is not provided, the client only reads cached files from disk.
Public Instance Methods
Source
# File lib/rubygems/compact_index_client.rb, line 81 def available? Gem::CompactIndexClient.debug { "available?" } @parser.available? end
Source
# File lib/rubygems/compact_index_client.rb, line 57 def dependencies(names) Gem::CompactIndexClient.debug { "dependencies(#{names})" } names.map {|name| info(name) } end
Source
# File lib/rubygems/compact_index_client.rb, line 71 def fetch_info(name) Gem::CompactIndexClient.debug { "fetch_info(#{name})" } @parser.parse_info(@cache.fetch_info(name), name) end
Fetches a single gem’s info without consulting the versions index, using a conditional request to refresh the cached file. Useful when only a few gems are needed and the versions index download would dominate, as in gem install.
Source
# File lib/rubygems/compact_index_client.rb, line 62 def info(name) Gem::CompactIndexClient.debug { "info(#{name})" } @parser.info(name) end
Source
# File lib/rubygems/compact_index_client.rb, line 76 def latest_version(name) Gem::CompactIndexClient.debug { "latest_version(#{name})" } @parser.info(name).map {|d| Gem::Version.new(d[INFO_VERSION]) }.max end
Source
# File lib/rubygems/compact_index_client.rb, line 47 def names Gem::CompactIndexClient.debug { "names" } @parser.names end
Source
# File lib/rubygems/compact_index_client.rb, line 86 def reset! Gem::CompactIndexClient.debug { "reset!" } @cache.reset! end
Source
# File lib/rubygems/compact_index_client.rb, line 52 def versions Gem::CompactIndexClient.debug { "versions" } @parser.versions end