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

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 42

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 24

def self.debug
  return unless ENV["DEBUG_COMPACT_INDEX"]
  DEBUG_MUTEX.synchronize { warn("[#{self}] #{yield}") }
end

Instance Attribute Details

#available?Boolean (readonly)

[ GitHub ]

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

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

Instance Method Details

#dependencies(names)

[ GitHub ]

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

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 71

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 62

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

#latest_version(name)

[ GitHub ]

  
# 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

#names

[ GitHub ]

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

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

#reset!

[ GitHub ]

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

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

#versions

[ GitHub ]

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

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