class Bundler::Checksum::Store
属性
store[R]
公共类方法
new() 点击切换源代码
# File bundler/checksum.rb, line 170 def initialize @store = {} @store_mutex = Mutex.new end
公共实例方法
inspect() 点击切换源代码
# File bundler/checksum.rb, line 175 def inspect "#<#{self.class}:#{object_id} size=#{store.size}>" end
merge!(other) 点击切换源代码
# File 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
register(spec, checksum) 点击切换源代码
# File bundler/checksum.rb, line 204 def register(spec, checksum) return unless checksum register_checksum(spec.name_tuple.lock_name, checksum) end
replace(spec, checksum) 点击切换源代码
当新校验和来自同一来源时进行替换。主要目的是注册来自索引中存在重复 gem (根据 full_name)的 gem 的校验和。
特别地,当 2 个 gem 有两个相似的平台时,例如 “darwin20” 和 “darwin-20”,它们都解析为 darwin-20。在 Index
中,后面的 gem 替换了前面的 gem,所以我们在这里也这样做。
但是,如果新的校验和来自不同的来源,我们将像往常一样注册。这确保了在存在多个包含具有不同校验和的相同 gem 的顶级源的情况下发生不匹配错误。
# File 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
to_lock(spec) 点击切换源代码
# File 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
私有实例方法
fetch_checksum(lock_name, algo) 点击切换源代码
# File bundler/checksum.rb, line 249 def fetch_checksum(lock_name, algo) @store[lock_name]&.fetch(algo, nil) end
merge_checksum(lock_name, checksum, existing) 点击切换源代码
# File bundler/checksum.rb, line 241 def merge_checksum(lock_name, checksum, existing) existing.merge!(checksum) || raise(ChecksumMismatchError.new(lock_name, existing, checksum)) end
register_checksum(lock_name, checksum) 点击切换源代码
# File 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
store_checksum(lock_name, checksum) 点击切换源代码
# File bundler/checksum.rb, line 245 def store_checksum(lock_name, checksum) (@store[lock_name] ||= {})[checksum.algo] = checksum end