Module: Gibbler::Object
- Defined in:
- lib/gibbler.rb,
lib/gibbler/aliases.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#__gibbler(h = self) ⇒ Object
Creates a digest for the current state of self based on: * Object#class * Length of Object#name || 0 * Object#name || ”.
-
#digest_cache ⇒ Object
The cache is in the Attic.
-
#freeze ⇒ Object
A simple override on Object#freeze to create a digest before the object is frozen.
-
#gibbled? ⇒ Boolean
(also: #changed?)
Has this object been modified?.
-
#gibbler ⇒ Object
(also: #digest)
Calculates a digest for the current object instance.
- #gibbler_debug(*args) ⇒ Object
- #gibbler_fields ⇒ Object (also: #digest_fields)
Class Method Details
.gibbler_fields ⇒ Object
102 103 |
# File 'lib/gibbler.rb', line 102 def self.gibbler_fields end |
.included(obj) ⇒ Object
95 96 97 98 99 100 |
# File 'lib/gibbler.rb', line 95 def self.included(obj) obj.extend Attic obj.attic :gibbler_cache # Backwards compatibility for <= 0.6.2 obj.send :alias_method, :__gibbler_cache, :gibbler_cache end |
Instance Method Details
#__gibbler(h = self) ⇒ Object
Creates a digest for the current state of self based on:
-
Object#class
-
Length of Object#name || 0
-
Object#name || ”
e.g. Digest::SHA1.hexdigest “Class:6:Object” #=>
This is a default method appropriate for only the most basic objects like Class and Module.
156 157 158 159 160 161 162 163 |
# File 'lib/gibbler.rb', line 156 def __gibbler(h=self) klass = h.class nom = h.name if h.respond_to?(:name) nom ||= '' a = Gibbler.digest '%s:%s:%s' % [klass, nom.size, nom] gibbler_debug klass, a, [klass, nom.size, nom] a end |
#digest_cache ⇒ Object
The cache is in the Attic.
12 |
# File 'lib/gibbler/aliases.rb', line 12 def digest_cache; gibbler_cache; end |
#freeze ⇒ Object
A simple override on Object#freeze to create a digest before the object is frozen. Once the object is frozen obj.gibbler
will return the cached value with out calculation.
169 170 171 172 173 174 |
# File 'lib/gibbler.rb', line 169 def freeze() #gibbler_debug :freeze, caller[0] self.gibbler super self end |
#gibbled? ⇒ Boolean Also known as: changed?
Has this object been modified?
This method compares the return value from digest with the previous value returned by gibbler (the value is stored in the attic as gibbler_cache
). See Attic
134 135 136 137 138 139 |
# File 'lib/gibbler.rb', line 134 def gibbled? self.gibbler_cache ||= self.gibbler was, now = self.gibbler_cache.clone, self.gibbler gibbler_debug :gibbled?, was, now was != now end |
#gibbler ⇒ Object Also known as: digest
Calculates a digest for the current object instance. Objects that are a kind of Hash or Array are processed recursively. The length of the returned String depends on the digest type. Also stores the value in the attic.
obj.gibbler # => a5b1191a
obj.gibbler_cache # => a5b1191a
Calling gibbler_cache returns the most recent digest without calculation.
If the object is frozen, this will return the value of gibbler_cache
.
121 122 123 124 125 126 |
# File 'lib/gibbler.rb', line 121 def gibbler #gibbler_debug caller[0] gibbler_debug :GIBBLER, self.class, self return self.gibbler_cache if self.frozen? self.gibbler_cache = Gibbler::Digest.new self.__gibbler end |
#gibbler_debug(*args) ⇒ Object
141 142 143 144 |
# File 'lib/gibbler.rb', line 141 def gibbler_debug(*args) return unless Gibbler.debug? p args end |
#gibbler_fields ⇒ Object Also known as: digest_fields
104 105 |
# File 'lib/gibbler.rb', line 104 def gibbler_fields end |