Class: Bundler::CompactIndexClient

Inherits:
Object
  • Object
show all
Defined in:
lib/bundler/compact_index_client.rb,
lib/bundler/compact_index_client/cache.rb,
lib/bundler/compact_index_client/updater.rb,
lib/bundler/compact_index_client/cache_file.rb,
lib/bundler/compact_index_client/gem_parser.rb

Defined Under Namespace

Classes: Cache, CacheFile, Error, GemParser, Updater

Constant Summary collapse

SUPPORTED_DIGESTS =

NOTE: MD5 is here not because we expect a server to respond with it, but because we use it to generate the etag on first request during the upgrade to the compact index client that uses opaque etags saved to files. Remove once 2.5.0 has been out for a while.

{ "sha-256" => :SHA256, "md5" => :MD5 }.freeze
DEBUG_MUTEX =
Thread::Mutex.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(directory, fetcher) ⇒ CompactIndexClient

Returns a new instance of CompactIndexClient.



28
29
30
31
32
33
34
35
36
# File 'lib/bundler/compact_index_client.rb', line 28

def initialize(directory, fetcher)
  @directory = Pathname.new(directory)
  @updater = Updater.new(fetcher)
  @cache = Cache.new(@directory)
  @endpoints = Set.new
  @info_checksums_by_name = {}
  @parsed_checksums = false
  @mutex = Thread::Mutex.new
end

Instance Attribute Details

#directoryObject (readonly)

Returns the value of attribute directory.



26
27
28
# File 'lib/bundler/compact_index_client.rb', line 26

def directory
  @directory
end

Class Method Details

.debugObject



15
16
17
18
# File 'lib/bundler/compact_index_client.rb', line 15

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

Instance Method Details

#dependencies(names) ⇒ Object



75
76
77
78
79
80
81
# File 'lib/bundler/compact_index_client.rb', line 75

def dependencies(names)
  Bundler::CompactIndexClient.debug { "dependencies(#{names})" }
  execution_mode.call(names) do |name|
    update_info(name)
    @cache.dependencies(name).map {|d| d.unshift(name) }
  end.flatten(1)
end

#execution_modeLambda

Returns A lambda that takes an array of inputs and a block, and maps the inputs with the block in parallel.

Returns:

  • (Lambda)

    A lambda that takes an array of inputs and a block, and maps the inputs with the block in parallel.



48
49
50
# File 'lib/bundler/compact_index_client.rb', line 48

def execution_mode
  @execution_mode || sequentially
end

#execution_mode=(block) ⇒ Object



38
39
40
41
42
43
# File 'lib/bundler/compact_index_client.rb', line 38

def execution_mode=(block)
  Bundler::CompactIndexClient.debug { "execution_mode=" }
  @endpoints = Set.new

  @execution_mode = block
end

#namesObject



62
63
64
65
66
# File 'lib/bundler/compact_index_client.rb', line 62

def names
  Bundler::CompactIndexClient.debug { "/names" }
  update("names", @cache.names_path, @cache.names_etag_path)
  @cache.names
end

#sequential_execution_mode!Object



52
53
54
# File 'lib/bundler/compact_index_client.rb', line 52

def sequential_execution_mode!
  self.execution_mode = sequentially
end

#sequentiallyObject



56
57
58
59
60
# File 'lib/bundler/compact_index_client.rb', line 56

def sequentially
  @sequentially ||= lambda do |inputs, &blk|
    inputs.map(&blk)
  end
end

#update_and_parse_checksums!Object



83
84
85
86
87
88
89
# File 'lib/bundler/compact_index_client.rb', line 83

def update_and_parse_checksums!
  Bundler::CompactIndexClient.debug { "update_and_parse_checksums!" }
  return @info_checksums_by_name if @parsed_checksums
  update("versions", @cache.versions_path, @cache.versions_etag_path)
  @info_checksums_by_name = @cache.checksums
  @parsed_checksums = true
end

#versionsObject



68
69
70
71
72
73
# File 'lib/bundler/compact_index_client.rb', line 68

def versions
  Bundler::CompactIndexClient.debug { "/versions" }
  update("versions", @cache.versions_path, @cache.versions_etag_path)
  versions, @info_checksums_by_name = @cache.versions
  versions
end