diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-07-17 14:53:41 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-07-17 14:55:28 -0300 |
commit | 1a300b674810b85e6f55e4106cb27c1b2dbef499 (patch) | |
tree | 33e31312db60c600a5346ea27e674d53bcb2e857 /activemodel/lib/active_model/dirty.rb | |
parent | 2888f8653e2e0a6394e41cb4e8db2e2d81313eb7 (diff) | |
download | rails-1a300b674810b85e6f55e4106cb27c1b2dbef499.tar.gz rails-1a300b674810b85e6f55e4106cb27c1b2dbef499.tar.bz2 rails-1a300b674810b85e6f55e4106cb27c1b2dbef499.zip |
Make restore_attributes public
Also make it accept a list of attributes to be changed. This will make
possible to restore only a subset of the changed attributes.
Closes #16203
Diffstat (limited to 'activemodel/lib/active_model/dirty.rb')
-rw-r--r-- | activemodel/lib/active_model/dirty.rb | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/activemodel/lib/active_model/dirty.rb b/activemodel/lib/active_model/dirty.rb index 24214187af..d11243c4c0 100644 --- a/activemodel/lib/active_model/dirty.rb +++ b/activemodel/lib/active_model/dirty.rb @@ -180,6 +180,11 @@ module ActiveModel attribute_changed?(attr) ? changed_attributes[attr] : __send__(attr) end + # Restore all previous data of the provided attributes. + def restore_attributes(attributes = changed) + attributes.each { |attr| restore_attribute! attr } + end + private # Removes current changes and makes them accessible through +previous_changes+. @@ -199,11 +204,6 @@ module ActiveModel clear_changes_information end - # Restore all previous data. - def restore_attributes # :doc: - changed_attributes.each_key { |attr| restore_attribute! attr } - end - # Handle <tt>*_change</tt> for +method_missing+. def attribute_change(attr) [changed_attributes[attr], __send__(attr)] if attribute_changed?(attr) |