diff options
author | Sam Pohlenz <sam@sampohlenz.com> | 2010-04-01 21:16:03 +1030 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2010-04-01 17:52:45 -0700 |
commit | 3adaef8ae73a3061a9fe4c5e0256d80bc09b1cf4 (patch) | |
tree | d6b4be65ec8e2d72554fe110f22415e44a1b6919 /activemodel/lib/active_model | |
parent | dc5300adb6d46252c26e239ac67e3ca6e5e2d77b (diff) | |
download | rails-3adaef8ae73a3061a9fe4c5e0256d80bc09b1cf4.tar.gz rails-3adaef8ae73a3061a9fe4c5e0256d80bc09b1cf4.tar.bz2 rails-3adaef8ae73a3061a9fe4c5e0256d80bc09b1cf4.zip |
Restore changed_attributes method in ActiveModel::Dirty and loosen expectation on including class' initialize method.
[#4308 state:committed]
Signed-off-by: Jeremy Kemper <jeremy@bitsweat.net>
Diffstat (limited to 'activemodel/lib/active_model')
-rw-r--r-- | activemodel/lib/active_model/dirty.rb | 24 |
1 files changed, 12 insertions, 12 deletions
diff --git a/activemodel/lib/active_model/dirty.rb b/activemodel/lib/active_model/dirty.rb index 2d5acdfced..a7ee15a7f6 100644 --- a/activemodel/lib/active_model/dirty.rb +++ b/activemodel/lib/active_model/dirty.rb @@ -91,17 +91,12 @@ module ActiveModel attribute_method_affix :prefix => 'reset_', :suffix => '!' end - def initialize(*) - @changed_attributes = {} - super - end - # Do any attributes have unsaved changes? # person.changed? # => false # person.name = 'bob' # person.changed? # => true def changed? - !@changed_attributes.empty? + !changed_attributes.empty? end # List of attributes with unsaved changes. @@ -109,7 +104,7 @@ module ActiveModel # person.name = 'bob' # person.changed # => ['name'] def changed - @changed_attributes.keys + changed_attributes.keys end # Map of changed attrs => [original value, new value]. @@ -130,19 +125,24 @@ module ActiveModel end private + # Map of change <tt>attr => original value</tt>. + def changed_attributes + @changed_attributes ||= {} + end + # Handle <tt>*_changed?</tt> for +method_missing+. def attribute_changed?(attr) - @changed_attributes.include?(attr) + changed_attributes.include?(attr) end # Handle <tt>*_change</tt> for +method_missing+. def attribute_change(attr) - [@changed_attributes[attr], __send__(attr)] if attribute_changed?(attr) + [changed_attributes[attr], __send__(attr)] if attribute_changed?(attr) end # Handle <tt>*_was</tt> for +method_missing+. def attribute_was(attr) - attribute_changed?(attr) ? @changed_attributes[attr] : __send__(attr) + attribute_changed?(attr) ? changed_attributes[attr] : __send__(attr) end # Handle <tt>*_will_change!</tt> for +method_missing+. @@ -153,12 +153,12 @@ module ActiveModel rescue TypeError, NoMethodError end - @changed_attributes[attr] = value + changed_attributes[attr] = value end # Handle <tt>reset_*!</tt> for +method_missing+. def reset_attribute!(attr) - __send__("#{attr}=", @changed_attributes[attr]) if attribute_changed?(attr) + __send__("#{attr}=", changed_attributes[attr]) if attribute_changed?(attr) end end end |