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

- old
+ new

@@ -1,10 +1,11 @@ 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 @@ -48,9 +49,14 @@ # person.changes # => {} # person.name = 'bob' # 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) + 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) \ No newline at end of file