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



482
483
484
485
# File 'lib/gibbler.rb', line 482

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.



488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
# File 'lib/gibbler.rb', line 488

def __gibbler(digest_type=nil)
  klass = self.class
  d, index = [], 0
  self.each_with_index do |value,idx| 
    unless value.respond_to? :__gibbler
      gibbler_debug klass, :skipping, idx
      next
    end
    d << '%s:%s:%s' % [value.class, index, value.__gibbler(digest_type)]
    index += 1
  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