class Bundler::Checksum

Constants

ALGO_SEPARATOR
DEFAULT_ALGORITHM
DEFAULT_BLOCK_SIZE

Attributes

algo[R]
digest[R]
sources[R]

Public Class Methods

from_api(digest, source_uri, algo = DEFAULT_ALGORITHM) click to toggle source
# File bundler/checksum.rb, line 19
def from_api(digest, source_uri, algo = DEFAULT_ALGORITHM)
  Checksum.new(algo, to_hexdigest(digest, algo), Source.new(:api, source_uri))
end
from_gem(io, pathname, algo = DEFAULT_ALGORITHM) click to toggle source
# File bundler/checksum.rb, line 12
def from_gem(io, pathname, algo = DEFAULT_ALGORITHM)
  digest = Bundler::SharedHelpers.digest(algo.upcase).new
  buf = String.new(:capacity => DEFAULT_BLOCK_SIZE)
  digest << io.readpartial(DEFAULT_BLOCK_SIZE, buf) until io.eof?
  Checksum.new(algo, digest.hexdigest!, Source.new(:gem, pathname))
end
from_lock(lock_checksum, lockfile_location) click to toggle source
# File bundler/checksum.rb, line 23
def from_lock(lock_checksum, lockfile_location)
  algo, digest = lock_checksum.strip.split(ALGO_SEPARATOR, 2)
  Checksum.new(algo, to_hexdigest(digest, algo), Source.new(:lock, lockfile_location))
end
new(algo, digest, source) click to toggle source
# File bundler/checksum.rb, line 42
def initialize(algo, digest, source)
  @algo = algo
  @digest = digest
  @sources = [source]
end
to_hexdigest(digest, algo = DEFAULT_ALGORITHM) click to toggle source
# File bundler/checksum.rb, line 28
def to_hexdigest(digest, algo = DEFAULT_ALGORITHM)
  return digest unless algo == DEFAULT_ALGORITHM
  return digest if digest.match?(/\A[0-9a-f]{64}\z/i)
  if digest.match?(%r{\A[-0-9a-z_+/]{43}={0,2}\z}i)
    digest = digest.tr("-_", "+/") # fix urlsafe base64
    # transform to hex. Use unpack1 when we drop older rubies
    return digest.unpack("m0").first.unpack("H*").first
  end
  raise ArgumentError, "#{digest.inspect} is not a valid SHA256 hex or base64 digest"
end

Public Instance Methods

==(other) click to toggle source
# File bundler/checksum.rb, line 48
def ==(other)
  match?(other) && other.sources == sources
end
Also aliased as: eql?
eql?(other)
Alias for: ==
formatted_sources() click to toggle source
# File bundler/checksum.rb, line 76
def formatted_sources
  sources.join("\n    and ").concat("\n")
end
hash() click to toggle source
# File bundler/checksum.rb, line 58
def hash
  digest.hash
end
inspect() click to toggle source
# File bundler/checksum.rb, line 94
def inspect
  abbr = "#{algo}#{ALGO_SEPARATOR}#{digest[0, 8]}"
  from = "from #{sources.join(" and ")}"
  "#<#{self.class}:#{object_id} #{abbr} #{from}>"
end
match?(other) click to toggle source
# File bundler/checksum.rb, line 54
def match?(other)
  other.is_a?(self.class) && other.digest == digest && other.algo == algo
end
merge!(other) click to toggle source
# File bundler/checksum.rb, line 70
def merge!(other)
  return nil unless match?(other)
  @sources.concat(other.sources).uniq!
  self
end
removable?() click to toggle source
# File bundler/checksum.rb, line 80
def removable?
  sources.all?(&:removable?)
end
removal_instructions() click to toggle source
# File bundler/checksum.rb, line 84
def removal_instructions
  msg = +""
  i = 1
  sources.each do |source|
    msg << "  #{i}. #{source.removal}\n"
    i += 1
  end
  msg << "  #{i}. run `bundle install`\n"
end
to_lock() click to toggle source
# File bundler/checksum.rb, line 66
def to_lock
  "#{algo}#{ALGO_SEPARATOR}#{digest}"
end
to_s() click to toggle source
# File bundler/checksum.rb, line 62
def to_s
  "#{to_lock} (from #{sources.first}#{", ..." if sources.size > 1})"
end