Class: Bundler::CompactIndexClient
- Inherits:
-
Object
- Object
- Bundler::CompactIndexClient
- Defined in:
- lib/bundler/compact_index_client.rb,
lib/bundler/compact_index_client/cache.rb,
lib/bundler/compact_index_client/parser.rb,
lib/bundler/compact_index_client/updater.rb,
lib/bundler/compact_index_client/cache_file.rb
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.
Defined Under Namespace
Classes: Cache, CacheFile, Error, Parser, Updater
Constant Summary collapse
- SUPPORTED_DIGESTS =
{ "sha-256" => :SHA256 }.freeze
- DEBUG_MUTEX =
Thread::Mutex.new
- INFO_NAME =
info returns an Array of INFO Arrays. Each INFO Array has the following indices:
0
- INFO_VERSION =
1
- INFO_PLATFORM =
2
- INFO_DEPS =
3
- INFO_REQS =
4
Class Method Summary collapse
Instance Method Summary collapse
- #available? ⇒ Boolean
- #dependencies(names) ⇒ Object
- #info(name) ⇒ Object
-
#initialize(directory, fetcher = nil) ⇒ CompactIndexClient
constructor
A new instance of CompactIndexClient.
- #latest_version(name) ⇒ Object
- #names ⇒ Object
- #reset! ⇒ Object
- #versions ⇒ Object
Constructor Details
#initialize(directory, fetcher = nil) ⇒ CompactIndexClient
Returns a new instance of CompactIndexClient.
53 54 55 56 |
# File 'lib/bundler/compact_index_client.rb', line 53 def initialize(directory, fetcher = nil) @cache = Cache.new(directory, fetcher) @parser = Parser.new(@cache) end |
Class Method Details
.debug ⇒ Object
41 42 43 44 |
# File 'lib/bundler/compact_index_client.rb', line 41 def self.debug return unless ENV["DEBUG_COMPACT_INDEX"] DEBUG_MUTEX.synchronize { warn("[#{self}] #{yield}") } end |
Instance Method Details
#available? ⇒ Boolean
83 84 85 86 |
# File 'lib/bundler/compact_index_client.rb', line 83 def available? Bundler::CompactIndexClient.debug { "available?" } @parser.available? end |
#dependencies(names) ⇒ Object
68 69 70 71 |
# File 'lib/bundler/compact_index_client.rb', line 68 def dependencies(names) Bundler::CompactIndexClient.debug { "dependencies(#{names})" } names.map {|name| info(name) } end |
#info(name) ⇒ Object
73 74 75 76 |
# File 'lib/bundler/compact_index_client.rb', line 73 def info(name) Bundler::CompactIndexClient.debug { "info(#{name})" } @parser.info(name) end |
#latest_version(name) ⇒ Object
78 79 80 81 |
# File 'lib/bundler/compact_index_client.rb', line 78 def latest_version(name) Bundler::CompactIndexClient.debug { "latest_version(#{name})" } @parser.info(name).map {|d| Gem::Version.new(d[INFO_VERSION]) }.max end |
#names ⇒ Object
58 59 60 61 |
# File 'lib/bundler/compact_index_client.rb', line 58 def names Bundler::CompactIndexClient.debug { "names" } @parser.names end |
#reset! ⇒ Object
88 89 90 91 |
# File 'lib/bundler/compact_index_client.rb', line 88 def reset! Bundler::CompactIndexClient.debug { "reset!" } @cache.reset! end |
#versions ⇒ Object
63 64 65 66 |
# File 'lib/bundler/compact_index_client.rb', line 63 def versions Bundler::CompactIndexClient.debug { "versions" } @parser.versions end |