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
438 439 440 441 |
# File 'lib/gibbler.rb', line 438 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.
444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 |
# File 'lib/gibbler.rb', line 444 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] unless value.respond_to? :__gibbler gibbler_debug klass, :skipping, name next end '%s:%s:%s' % [value.class, name, value.__gibbler(digest_type)] end d = d.join(Gibbler.delimiter).__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 |