class Bundler::Checksum::Store

Attributes

store[R]

Public Class Methods

new() click to toggle source
# File bundler/checksum.rb, line 150
def initialize
  @store = {}
end

Public Instance Methods

fetch(spec, algo = DEFAULT_ALGORITHM) click to toggle source
# File bundler/checksum.rb, line 165
def fetch(spec, algo = DEFAULT_ALGORITHM)
  store[spec.name_tuple]&.fetch(algo, nil)
end
initialize_copy(other) click to toggle source
# File bundler/checksum.rb, line 154
def initialize_copy(other)
  @store = {}
  other.store.each do |name_tuple, checksums|
    store[name_tuple] = checksums.dup
  end
end
inspect() click to toggle source
# File bundler/checksum.rb, line 161
def inspect
  "#<#{self.class}:#{object_id} size=#{store.size}>"
end
merge!(other) click to toggle source
# File bundler/checksum.rb, line 201
def merge!(other)
  other.store.each do |name_tuple, checksums|
    checksums.each do |_algo, checksum|
      register_checksum(name_tuple, checksum)
    end
  end
end
register(spec, checksum) click to toggle source
# File bundler/checksum.rb, line 195
def register(spec, checksum)
  return if Bundler.settings[:disable_checksum_validation]
  return unless checksum
  register_checksum(spec.name_tuple, checksum)
end
replace(spec, checksum) click to toggle source

Replace when the new checksum is from the same source. The primary purpose of this 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 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 bundler/checksum.rb, line 179
def replace(spec, checksum)
  return if Bundler.settings[:disable_checksum_validation]
  return unless checksum

  name_tuple = spec.name_tuple
  checksums = (store[name_tuple] ||= {})
  existing = checksums[checksum.algo]

  # we assume only one source because this is used while building the index
  if !existing || existing.sources.first == checksum.sources.first
    checksums[checksum.algo] = checksum
  else
    register_checksum(name_tuple, checksum)
  end
end
to_lock(spec) click to toggle source
# File bundler/checksum.rb, line 209
def to_lock(spec)
  name_tuple = spec.name_tuple
  if checksums = store[name_tuple]
    "#{name_tuple.lock_name} #{checksums.values.map(&:to_lock).sort.join(",")}"
  else
    name_tuple.lock_name
  end
end

Private Instance Methods

register_checksum(name_tuple, checksum) click to toggle source
# File bundler/checksum.rb, line 220
def register_checksum(name_tuple, checksum)
  return unless checksum
  checksums = (store[name_tuple] ||= {})
  existing = checksums[checksum.algo]

  if !existing
    checksums[checksum.algo] = checksum
  elsif existing.merge!(checksum)
    checksum
  else
    raise ChecksumMismatchError.new(name_tuple, existing, checksum)
  end
end