diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2014-08-17 12:53:15 -0700 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2014-08-17 12:53:15 -0700 |
commit | 8f15565de879bd40c8390884d1d31e52de240323 (patch) | |
tree | c6c30c4a07a5d11f46d50853613b909ee0e8c6ae /activemodel/lib | |
parent | 9f6e82ee4783e491c20f5244a613fdeb4024beb5 (diff) | |
parent | e158ee50e64e2ae2460cd26be53039922f588300 (diff) | |
download | rails-8f15565de879bd40c8390884d1d31e52de240323.tar.gz rails-8f15565de879bd40c8390884d1d31e52de240323.tar.bz2 rails-8f15565de879bd40c8390884d1d31e52de240323.zip |
Merge branch 'master' of github.com:rails/rails
Diffstat (limited to 'activemodel/lib')
-rw-r--r-- | activemodel/lib/active_model/dirty.rb | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/activemodel/lib/active_model/dirty.rb b/activemodel/lib/active_model/dirty.rb index d11243c4c0..ca04f48c1c 100644 --- a/activemodel/lib/active_model/dirty.rb +++ b/activemodel/lib/active_model/dirty.rb @@ -219,7 +219,7 @@ module ActiveModel rescue TypeError, NoMethodError end - changed_attributes[attr] = value + set_attribute_was(attr, value) end # Handle <tt>reset_*!</tt> for +method_missing+. @@ -233,8 +233,22 @@ module ActiveModel def restore_attribute!(attr) if attribute_changed?(attr) __send__("#{attr}=", changed_attributes[attr]) - changed_attributes.delete(attr) + clear_attribute_changes([attr]) end end + + # This is necessary because `changed_attributes` might be overridden in + # other implemntations (e.g. in `ActiveRecord`) + alias_method :attributes_changed_by_setter, :changed_attributes # :nodoc: + + # Force an attribute to have a particular "before" value + def set_attribute_was(attr, old_value) + attributes_changed_by_setter[attr] = old_value + end + + # Remove changes information for the provided attributes. + def clear_attribute_changes(attributes) + attributes_changed_by_setter.except!(*attributes) + end end end |