Module: Gibbler::Hash
Overview
Creates a digest based on:
-
parse each key, value pair into an Array containing keys:
CLASS:KEY:VALUE.__gibbler
-
The gibbler method is called on each element so if it is a Hash or Array etc it will be parsed recursively according to the gibbler method for that class type.
-
-
Digest the Array of digests
-
Return the digest for
class:length:value
where:-
“class” is equal to the current object class (e.g. Hash).
-
“length” is the size of the Array of digests (which should equal the number of keys in the original Hash object).
-
“value” is the Array of digests joined with a colon (“:”).
-
This method can be used by any class with a keys
method.
class MyOrderedHash
include Gibbler::Hash
end
Class Method Summary collapse
Instance Method Summary collapse
-
#__gibbler(digest_type = nil) ⇒ Object
Creates a digest for the current state of self.
Methods included from Object
#digest_cache, #freeze, #gibbled?, #gibbler, #gibbler_debug, #gibbler_fields, gibbler_fields
Class Method Details
.included(obj) ⇒ Object
403 404 405 406 |
# File 'lib/gibbler.rb', line 403 def self.included(obj) obj.extend Attic obj.attic :gibbler_cache end |
Instance Method Details
#__gibbler(digest_type = nil) ⇒ Object
Creates a digest for the current state of self.
409 410 411 412 413 414 415 416 417 418 419 420 |
# File 'lib/gibbler.rb', line 409 def __gibbler(digest_type=nil) klass = self.class d = self.keys.sort { |a,b| a.inspect <=> b.inspect } d.collect! do |name| value = self[name] '%s:%s:%s' % [value.class, name, value.__gibbler(digest_type)] end d = d.join(':').__gibbler(digest_type) a = Gibbler.digest '%s:%s:%s' % [klass, d.size, d], digest_type gibbler_debug klass, a, [klass, d.size, d] a end |