From 90b47ef66fb2d065921e88926eb1f5c2222bd5f8 Mon Sep 17 00:00:00 2001 From: Alexander Lang Date: Fri, 18 Sep 2009 00:11:13 -0700 Subject: [PATCH] is again ruby 1.9 compatible --- CHANGES.md | 3 ++- lib/couch_potato/persistence/dirty_attributes.rb | 11 +++++++++++ lib/couch_potato/persistence/properties.rb | 2 +- lib/couch_potato/persistence/simple_property.rb | 12 ------------ 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 0dbe38f2..506cd1c8 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -8,4 +8,5 @@ * support attachments via the _attachments property * support for namespaces models * removed belongs_to macro for now -* removed CouchPotato::Config.database_server, just set CouchPotato::Config.database_name to the full url if you are not using localhost:5984 \ No newline at end of file +* removed CouchPotato::Config.database_server, just set CouchPotato::Config.database_name to the full url if you are not using localhost:5984 +* Ruby 1.9 was broken and is now working again \ No newline at end of file diff --git a/lib/couch_potato/persistence/dirty_attributes.rb b/lib/couch_potato/persistence/dirty_attributes.rb index 8afb4b14..a7835dff 100644 --- a/lib/couch_potato/persistence/dirty_attributes.rb +++ b/lib/couch_potato/persistence/dirty_attributes.rb @@ -5,6 +5,11 @@ module DirtyAttributes def self.included(base) base.class_eval do after_save :reset_dirty_attributes + + def initialize(attributes = {}) + super + assign_attribute_copies_for_dirty_tracking + end end end @@ -17,6 +22,12 @@ def dirty? private + def assign_attribute_copies_for_dirty_tracking + attributes.each do |name, value| + self.instance_variable_set("@#{name}_was", clone_attribute(value)) + end if attributes + end + def reset_dirty_attributes self.class.properties.each do |property| instance_variable_set("@#{property.name}_was", clone_attribute(send(property.name))) diff --git a/lib/couch_potato/persistence/properties.rb b/lib/couch_potato/persistence/properties.rb index b117568c..f4570f8a 100644 --- a/lib/couch_potato/persistence/properties.rb +++ b/lib/couch_potato/persistence/properties.rb @@ -12,7 +12,7 @@ def self.properties end end end - + module ClassMethods # returns all the property names of a model class that have been defined using the #property method # diff --git a/lib/couch_potato/persistence/simple_property.rb b/lib/couch_potato/persistence/simple_property.rb index f40ce0d5..d69404ee 100644 --- a/lib/couch_potato/persistence/simple_property.rb +++ b/lib/couch_potato/persistence/simple_property.rb @@ -49,18 +49,6 @@ def accessors_module_for(clazz) def define_accessors(base, name, options) base.class_eval do attr_reader "#{name}_was" - - def initialize(attributes = {}) - super attributes - assign_attribute_copies_for_dirty_tracking - end - - def assign_attribute_copies_for_dirty_tracking - attributes.each do |name, value| - self.instance_variable_set("@#{name}_was", clone_attribute(value)) - end if attributes - end - private :assign_attribute_copies_for_dirty_tracking define_method "#{name}" do value = self.instance_variable_get("@#{name}")