Class: Buildr::Transports::Transport::Digester

Inherits:
Object
  • Object
show all
Defined in:
lib/core/transports.rb

Instance Method Summary collapse

Constructor Details

#initialize(types) ⇒ Digester

Returns a new instance of Digester.



199
200
201
202
203
204
205
# File 'lib/core/transports.rb', line 199

def initialize(types)
  types ||= [ "md5", "sha1" ]
  @digests = types.inject({}) do |hash, type|
    hash[type.to_s.downcase] = Digest.const_get(type.to_s.upcase).new
    hash
  end
end

Instance Method Details

#<<(bytes) ⇒ Object

Add bytes for digestion.



208
209
210
# File 'lib/core/transports.rb', line 208

def <<(bytes)
  @digests.each { |type, digest| digest << bytes }
end

#eachObject

Iterate over all the digests calling the block with two arguments: the digest type (e.g. “md5”) and the hexadecimal digest value.



214
215
216
# File 'lib/core/transports.rb', line 214

def each()
  @digests.each { |type, digest| yield type, digest.hexdigest }
end

#to_hashObject

Returns a hash that maps each digest type to its hexadecimal digest value.



219
220
221
222
223
224
# File 'lib/core/transports.rb', line 219

def to_hash()
  @digests.keys.inject({}) do |hash, type|
    hash[type] = @digests[type].hexdigest
    hash
  end
end