Module: Gibbler::Array

Includes:
Object
Included in:
Array
Defined in:
lib/gibbler.rb

Overview

Creates a digest based on:

  • parse each element into an Array of digests like: CLASS:INDEX: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. Array).

    • “length” is the size of the Array of digests (which should equal the number of elements in the original Array object).

    • “value” is the Array of digests joined with a colon (“:”).

This method can be used by any class with an each method.

class MyNamedArray 
  include Gibbler::Array
end

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Object

#digest_cache, #freeze, #gibbled?, #gibbler, #gibbler_debug, #gibbler_fields, gibbler_fields

Class Method Details

.included(obj) ⇒ Object



443
444
445
446
# File 'lib/gibbler.rb', line 443

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.



449
450
451
452
453
454
455
456
457
458
459
460
# File 'lib/gibbler.rb', line 449

def __gibbler(digest_type=nil)
  klass = self.class
  d, index = [], 0
  self.each do |value| 
    d << '%s:%s:%s' % [value.class, index, value.__gibbler(digest_type)]
    index += 1
  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