123456789_123456789_123456789_123456789_123456789_

Class: Gem::CompactIndexClient

Overview

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.

Constant Summary

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(directory, fetcher = nil) ⇒ CompactIndexClient

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.
[ GitHub ]

  
# File 'lib/rubygems/compact_index_client.rb', line 60

def initialize(directory, fetcher = nil)
  @cache = Cache.new(directory, fetcher)
  @parser = Parser.new(@cache)
end

Class Method Details

.debug

[ GitHub ]

  
# 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

.filesystem_access(path, action = :write, &block)

Filesystem reads and writes funnel through this hook so that a host (e.g. Bundler) can translate low-level Errno exceptions into its own friendlier errors. The default just yields the path.

[ GitHub ]

  
# 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

.filesystem_access=(hook)

[ GitHub ]

  
# File 'lib/rubygems/compact_index_client.rb', line 45

def self.filesystem_access=(hook)
  @filesystem_access = hook
end

Instance Attribute Details

#available?Boolean (readonly)

[ GitHub ]

  
# File 'lib/rubygems/compact_index_client.rb', line 99

def available?
  Gem::CompactIndexClient.debug { "available?" }
  @parser.available?
end

Instance Method Details

#dependencies(names)

[ GitHub ]

  
# File 'lib/rubygems/compact_index_client.rb', line 75

def dependencies(names)
  Gem::CompactIndexClient.debug { "dependencies(#{names})" }
  names.map {|name| info(name) }
end

#fetch_info(name)

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.

[ GitHub ]

  
# 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

#info(name)

[ GitHub ]

  
# File 'lib/rubygems/compact_index_client.rb', line 80

def info(name)
  Gem::CompactIndexClient.debug { "info(#{name})" }
  @parser.info(name)
end

#latest_version(name)

[ GitHub ]

  
# 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

#names

[ GitHub ]

  
# File 'lib/rubygems/compact_index_client.rb', line 65

def names
  Gem::CompactIndexClient.debug { "names" }
  @parser.names
end

#reset!

[ GitHub ]

  
# File 'lib/rubygems/compact_index_client.rb', line 104

def reset!
  Gem::CompactIndexClient.debug { "reset!" }
  @cache.reset!
end

#versions

[ GitHub ]

  
# File 'lib/rubygems/compact_index_client.rb', line 70

def versions
  Gem::CompactIndexClient.debug { "versions" }
  @parser.versions
end