Class: Buildr::Transports::Transport::Digester
- Inherits:
-
Object
- Object
- Buildr::Transports::Transport::Digester
- Defined in:
- lib/core/transports.rb
Instance Method Summary collapse
-
#<<(bytes) ⇒ Object
Add bytes for digestion.
-
#each ⇒ Object
Iterate over all the digests calling the block with two arguments: the digest type (e.g. “md5”) and the hexadecimal digest value.
-
#initialize(types) ⇒ Digester
constructor
A new instance of Digester.
-
#to_hash ⇒ Object
Returns a hash that maps each digest type to its hexadecimal digest value.
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 |
#each ⇒ Object
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_hash ⇒ Object
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 |