Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Removed Gibbler::Simple; Gibbler::Complex now checks has_method? and …

…will use that before instance variables
  • Loading branch information...
commit 03f518ef8a55e9390b32c0aecd9d05b98b8bd0fc 1 parent b23052c
@delano authored
View
3  CHANGES.txt
@@ -3,12 +3,13 @@ GIBBLER, CHANGES
#### 0.9.0 (2012-04-20) ###############################
+* FIXED: Gibbler::Complex now checks has_method? and will use that before instance variables.
* CHANGE: Gibbler is now a class which supplies the default standalone usage
* CHANGE: Ruby object mixins must now be explicitly loaded via "require 'gibbler/mixins'"
* CHANGE: Removed Gibbler.enable_debug/disable_debug
* CHANGE: Gibbler.digest now returns nil for an empty Array
* ADDED: Gibbler.delimiter
-* ADDED: Gibbler::Simple
+
#### 0.8.10 (2011-10-23) ###############################
View
63 lib/gibbler.rb
@@ -300,66 +300,9 @@ def self.included(obj)
raise "You probably want to include Gibbler::Complex or Gibbler::Object"
end
- # Creates a digest based on:
- module Simple
- include Gibbler::Object
- def self.included(obj)
- obj.extend Attic
- obj.attic :gibbler_cache
- obj.class_eval do
- @__gibbler_fields = []
- def self.gibbler_fields
- @__gibbler_fields
- end
- def self.gibbler *fields
- @__gibbler_fields.push *fields
- end
- def self.inherited(obj)
- obj.extend Attic
- obj.attic :gibbler_cache
- fields = @__gibbler_fields.clone
- obj.class_eval do
- @__gibbler_fields = fields
- end
- end
- end
- end
-
- def gibbler_fields
- [self.class.gibbler_fields].compact.flatten
- end
-
- # Creates a digest for the current state of self.
- def __gibbler(digest_type=nil)
- klass = self.class
- d = []
- gibbler_debug :gibbler_fields, gibbler_fields
- gibbler_fields.each do |n|
- value = respond_to?(n) ? send(n) : instance_variable_get("@#{n}")
- unless value.respond_to? :__gibbler
- gibbler_debug klass, :skipping, n
- next
- end
- d << '%s:%s:%s' % [value.class, n, value.__gibbler(digest_type)]
- end
- d = d.join(Gibbler.delimiter).__gibbler(digest_type)
- a = Gibbler.digest "%s:%d:%s" % [klass, d.size, d], digest_type
- gibbler_debug klass, a, [klass, d.size, d]
- a
- end
-
-
- 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
- end
# Creates a digest based on:
- # * An Array of instance variable names and values in the format: <tt>CLASS:LENGTH:VALUE</tt>
+ # * An Array of instance variable names or method names and values in the format: <tt>CLASS:LENGTH:VALUE</tt>
# * 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
@@ -377,7 +320,7 @@ def __gibbler_revert!
# end
#
module Complex
- include Gibbler::Simple
+ include Gibbler::Object
def self.included(obj)
obj.extend Attic
@@ -417,7 +360,7 @@ def __gibbler(digest_type=nil)
d = []
gibbler_debug :gibbler_fields, gibbler_fields
gibbler_fields.each do |n|
- value = instance_variable_get("@#{n}")
+ value = respond_to?(n) ? send(n) : instance_variable_get("@#{n}")
unless value.respond_to? :__gibbler
gibbler_debug klass, :skipping, n
next
View
28 try/13_simple_object_try.rb
@@ -1,28 +0,0 @@
-require 'gibbler/mixins'
-require 'time'
-
-# arbitrary objects can specify instance variables to gibbler
- class ::SimpleTest
- include Gibbler::Simple
- attr_accessor :roles
- attr_accessor :ready
- gibbler :roles
- end
- a = SimpleTest.new
- a.roles = [:jesse, :joey, :danny, :kimmy, :michelle, :dj, :stephanie]
- a.ready = true
- a.gibbler
-#=> "b0a659d02e854721f2c865f4eaaae97bfdeda33b"
-
-# arbitrary objects can append more instance variables later on
- class ::SimpleTest
- gibbler :stamp, :ready
- def stamp
- Time.parse('2009-08-25 16:43:53 UTC')
- end
- end
- a = SimpleTest.new
- a.roles = [:jesse, :joey, :danny, :kimmy, :michelle, :dj, :stephanie]
- a.ready = true
- a.gibbler
-#=> "5daf07b7aae043d0ea6b079a630e034dad7f5982"
View
4 try/17_complex_object_try.rb
@@ -19,10 +19,12 @@ class ::FullHouse
# arbitrary objects can append more instance variables later on
class ::FullHouse
gibbler :stamp, :ready
+ def stamp
+ Time.parse('2009-08-25 16:43:53 UTC')
+ end
end
a = FullHouse.new
a.roles = [:jesse, :joey, :danny, :kimmy, :michelle, :dj, :stephanie]
- a.stamp = Time.parse('2009-08-25 16:43:53 UTC')
a.ready = true
a.gibbler
#=> "fbdce0d97a856e7106bec418d585c914914b8aa5"
Please sign in to comment.
Something went wrong with that request. Please try again.