Gibbler::Object

Public Class Methods

gibbler_fields() click to toggle source
# File lib/gibbler.rb, line 143
def self.gibbler_fields
end
included(obj) click to toggle source
# File lib/gibbler.rb, line 136
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

Public Instance Methods

__gibbler(digest_type=nil) click to toggle source

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.

# File lib/gibbler.rb, line 197
def __gibbler(digest_type=nil)
  klass = self.class
  nom = self.name if self.respond_to?(:name)
  nom ||= ''
  a = Gibbler.digest '%s:%s:%s' % [klass, nom.size, nom], digest_type
  gibbler_debug klass, a, [klass, nom.size, nom]
  a
end
changed?() click to toggle source
Alias for: gibbled?
digest(digest_type=nil) click to toggle source
Alias for: gibbler
digest_cache() click to toggle source

The cache is in the Attic.

# File lib/gibbler/aliases.rb, line 12
def    digest_cache;     gibbler_cache;  end
digest_fields() click to toggle source
Alias for: gibbler_fields
freeze() click to toggle source

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.

# File lib/gibbler.rb, line 210
def freeze()
  gibbler_debug :FREEZE, self.class, caller[0] if Gibbler.debug?
  self.gibbler
  super
  self
end
gibbled?() click to toggle source

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

# File lib/gibbler.rb, line 175
def gibbled?
  self.gibbler_cache ||= self.gibbler
  was, now = self.gibbler_cache.clone, self.gibbler
  gibbler_debug :gibbled?, was, now
  was != now
end
Also aliased as: changed?
gibbler(digest_type=nil) click to toggle source

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.

# File lib/gibbler.rb, line 162
def gibbler(digest_type=nil)
  #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(digest_type)
end
Also aliased as: digest
gibbler_debug(*args) click to toggle source
# File lib/gibbler.rb, line 182
def gibbler_debug(*args)
  return unless Gibbler.debug?
  p args
end
gibbler_fields() click to toggle source
# File lib/gibbler.rb, line 145
def gibbler_fields
end
Also aliased as: digest_fields

[Validate]

Generated with the Darkfish Rdoc Generator 2.