Module: Gibbler::Complex

Includes:
Object
Defined in:
lib/gibbler.rb

Overview

Creates a digest based on:

  • An Array of instance variable names and values in the format: CLASS:LENGTH:VALUE

    • 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. FullHouse).

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

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

This method can be used by any class which stores values in instance variables.

class Episodes
  include Gibbler::Complex
  attr_accessor :season, :year, :cast
end

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Object

#gibbled?, #gibbler, #gibbler_debug

Class Method Details

.included(obj) ⇒ Object



86
87
88
89
# File 'lib/gibbler.rb', line 86

def self.included(obj)
  obj.extend Attic
  obj.attic :__gibbler_cache
end

Instance Method Details

#__gibbler(h = self) ⇒ Object

Creates a digest for the current state of self.



92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/gibbler.rb', line 92

def __gibbler(h=self)
  klass = h.class
  d = []
  instance_variables.each do |n|
    value = instance_variable_get(n)
    d << '%s:%s:%s' % [value.class, n, value.__gibbler]
  end
  d = d.join(':').__gibbler
  a = Gibbler.digest "%s:%d:%s" % [klass, d.size, d]
  gibbler_debug klass, a, [klass, d.size, d]
  a
end

#__gibbler_revert!Object



105
106
107
108
109
110
111
# File 'lib/gibbler.rb', line 105

def __gibbler_revert!
  state = self.gibbler_object self.__gibbler_cache
  state.instance_variables do |n|
    v = state.instance_variable_get n
    self.instance_variable_set v
  end
end