Class: Bundler::Checksum::Store
Relationships & Source Files | |
Inherits: | Object |
Defined in: | lib/bundler/checksum.rb |
Class Method Summary
- .new ⇒ Store constructor
Instance Attribute Summary
- #store readonly protected
Instance Method Summary
- #inspect
- #merge!(other)
- #register(spec, checksum)
-
#replace(spec, checksum)
Replace when the new checksum is from the same source.
- #to_lock(spec)
- #fetch_checksum(lock_name, algo) private
- #merge_checksum(lock_name, checksum, existing) private
- #register_checksum(lock_name, checksum) private
- #store_checksum(lock_name, checksum) private
Constructor Details
.new ⇒ Store
# File 'lib/bundler/checksum.rb', line 170
def initialize @store = {} @store_mutex = Mutex.new end
Instance Attribute Details
#store (readonly, protected)
[ GitHub ]# File 'lib/bundler/checksum.rb', line 167
attr_reader :store
Instance Method Details
#fetch_checksum(lock_name, algo) (private)
[ GitHub ]#inspect
[ GitHub ]# File 'lib/bundler/checksum.rb', line 175
def inspect "#<#{self.class}:#{object_id} size=#{store.size}>" end
#merge!(other)
[ GitHub ]# File 'lib/bundler/checksum.rb', line 210
def merge!(other) other.store.each do |lock_name, checksums| checksums.each do |_algo, checksum| register_checksum(lock_name, checksum) end end end
#merge_checksum(lock_name, checksum, existing) (private)
[ GitHub ]# File 'lib/bundler/checksum.rb', line 241
def merge_checksum(lock_name, checksum, existing) existing.merge!(checksum) || raise(ChecksumMismatchError.new(lock_name, existing, checksum)) end
#register(spec, checksum)
[ GitHub ]# File 'lib/bundler/checksum.rb', line 204
def register(spec, checksum) return unless checksum register_checksum(spec.name_tuple.lock_name, checksum) end
#register_checksum(lock_name, checksum) (private)
[ GitHub ]# File 'lib/bundler/checksum.rb', line 230
def register_checksum(lock_name, checksum) @store_mutex.synchronize do existing = fetch_checksum(lock_name, checksum.algo) if existing merge_checksum(lock_name, checksum, existing) else store_checksum(lock_name, checksum) end end end
#replace(spec, checksum)
Replace when the new checksum is from the same source. The primary purpose is registering checksums from gems where there are duplicates of the same gem (according to full_name) in the index.
In particular, this is when 2 gems have two similar platforms, e.g. “darwin20” and “darwin-20”, both of which resolve to darwin-20. In the ::Bundler::Index
, the later gem replaces the former, so we do that here.
However, if the new checksum is from a different source, we register like normal. This ensures a mismatch error where there are multiple top level sources that contain the same gem with different checksums.
# File 'lib/bundler/checksum.rb', line 190
def replace(spec, checksum) return unless checksum lock_name = spec.name_tuple.lock_name @store_mutex.synchronize do existing = fetch_checksum(lock_name, checksum.algo) if !existing || existing.same_source?(checksum) store_checksum(lock_name, checksum) else merge_checksum(lock_name, checksum, existing) end end end
#store_checksum(lock_name, checksum) (private)
[ GitHub ]# File 'lib/bundler/checksum.rb', line 245
def store_checksum(lock_name, checksum) (@store[lock_name] ||= {})[checksum.algo] = checksum end
#to_lock(spec)
[ GitHub ]# File 'lib/bundler/checksum.rb', line 218
def to_lock(spec) lock_name = spec.name_tuple.lock_name checksums = @store[lock_name] if checksums "#{lock_name} #{checksums.values.map(&:to_lock).sort.join(",")}" else lock_name end end