lib/mongo_mapper/dirty.rb in mongo_mapper-unstable-2009.10.12 vs lib/mongo_mapper/dirty.rb in mongo_mapper-unstable-2009.10.16

- old
+ new

@@ -1,16 +1,9 @@ module MongoMapper module Dirty DIRTY_SUFFIXES = ['_changed?', '_change', '_will_change!', '_was'] - def self.included(base) - base.alias_method_chain :initialize, :dirty - base.alias_method_chain :write_attribute, :dirty - base.alias_method_chain :save, :dirty - base.alias_method_chain :save!, :dirty - end - def method_missing(method, *args, &block) if method.to_s =~ /(_changed\?|_change|_will_change!|_was)$/ method_suffix = $1 key = method.to_s.gsub(method_suffix, '') @@ -51,30 +44,30 @@ # person.changes # => { 'name' => ['bill', 'bob'] } def changes changed.inject({}) { |h, attribute| h[attribute] = key_change(attribute); h } end - def initialize_with_dirty(attrs={}) - initialize_without_dirty(attrs) + def initialize(attrs={}) + super(attrs) changed_keys.clear unless new? end - + # Attempts to +save+ the record and clears changed keys if successful. - def save_with_dirty(*args) #:nodoc: - if status = save_without_dirty(*args) + def save(*args) + if status = super changed_keys.clear end status end # Attempts to <tt>save!</tt> the record and clears changed keys if successful. - def save_with_dirty!(*args) #:nodoc: - status = save_without_dirty!(*args) + def save!(*args) + status = super changed_keys.clear status end - + # <tt>reload</tt> the record and clears changed keys. # def reload_with_dirty(*args) #:nodoc: # record = reload_without_dirty(*args) # changed_keys.clear # record @@ -112,11 +105,11 @@ def key_will_change!(attribute) changed_keys[attribute] = clone_key_value(attribute) end # Wrap write_attribute to remember original key value. - def write_attribute_with_dirty(attribute, value) + def write_attribute(attribute, value) attribute = attribute.to_s # The key already has an unsaved change. if changed_keys.include?(attribute) old = changed_keys[attribute] @@ -125,11 +118,11 @@ old = clone_key_value(attribute) changed_keys[attribute] = old if value_changed?(attribute, old, value) end # Carry on. - write_attribute_without_dirty(attribute, value) + super(attribute, value) end def value_changed?(key_name, old, value) key = _keys[key_name] @@ -138,6 +131,6 @@ end old != value end end -end \ No newline at end of file +end