123456789_123456789_123456789_123456789_123456789_

Class: Bundler::CompactIndexClient

Overview

The CompactIndexClient is responsible for fetching and parsing the compact index.

The compact index is a set of caching optimized files that are used to fetch gem information. The files are:

  • names: a list of all gem names

  • versions: a list of all gem versions

  • info/: a list of all versions of a gem

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 an http response.

If the fetcher is not provided, the client will only read cached files from disk.

The client is organized into:

  • Updater: updates the cached files on disk using the fetcher.

  • Cache: calls the updater, caches files, read and return them from disk

  • Parser: parses the compact index file data

  • CacheFile: a concurrency safe file reader/writer that verifies checksums

The client is intended to optimize memory usage and performance. It is called 100s or 1000s of times, parsing files with hundreds of thousands of lines. It may be called concurrently without global interpreter lock in some Rubies. As a result, some methods may look more complex than necessary to save memory or time.

Constant Summary

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(directory, fetcher = nil) ⇒ CompactIndexClient

[ GitHub ]

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

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

Class Method Details

.debug

[ GitHub ]

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

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/bundler/compact_index_client.rb', line 87

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

Instance Method Details

#dependencies(names)

[ GitHub ]

  
# File 'lib/bundler/compact_index_client.rb', line 72

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

#info(name)

[ GitHub ]

  
# File 'lib/bundler/compact_index_client.rb', line 77

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

#latest_version(name)

[ GitHub ]

  
# File 'lib/bundler/compact_index_client.rb', line 82

def latest_version(name)
  Bundler::CompactIndexClient.debug { "latest_version(#{name})" }
  @parser.info(name).map {|d| Gem::Version.new(d[INFO_VERSION]) }.max
end

#names

[ GitHub ]

  
# File 'lib/bundler/compact_index_client.rb', line 62

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

#reset!

[ GitHub ]

  
# File 'lib/bundler/compact_index_client.rb', line 92

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

#versions

[ GitHub ]

  
# File 'lib/bundler/compact_index_client.rb', line 67

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