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 the single shared client: Bundler ships a copy of it and uses it underneath its own fetcher orchestration, injecting its fetcher and filesystem access hook.
Constants
Public Class Methods
Source
# File lib/rubygems/compact_index_client.rb, line 27 def self.debug return unless ENV["DEBUG_COMPACT_INDEX"] DEBUG_MUTEX.synchronize { warn("[#{self}] #{yield}") } end
# File lib/rubygems/compact_index_client.rb, line 37 def self.filesystem_access(path, action = :write, &block) if @filesystem_access @filesystem_access.call(path, action, &block) else yield path end end
Source
# File lib/rubygems/compact_index_client.rb, line 45 def self.filesystem_access=(hook) @filesystem_access = hook end
# File lib/rubygems/compact_index_client.rb, line 60 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 99 def available? Gem::CompactIndexClient.debug { "available?" } @parser.available? end
Source
# File lib/rubygems/compact_index_client.rb, line 75 def dependencies(names) Gem::CompactIndexClient.debug { "dependencies(#{names})" } names.map {|name| info(name) } end
Source
# File lib/rubygems/compact_index_client.rb, line 89 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 80 def info(name) Gem::CompactIndexClient.debug { "info(#{name})" } @parser.info(name) end
Source
# File lib/rubygems/compact_index_client.rb, line 94 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 65 def names Gem::CompactIndexClient.debug { "names" } @parser.names end
Source
# File lib/rubygems/compact_index_client.rb, line 104 def reset! Gem::CompactIndexClient.debug { "reset!" } @cache.reset! end
Source
# File lib/rubygems/compact_index_client.rb, line 70 def versions Gem::CompactIndexClient.debug { "versions" } @parser.versions end