aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel
diff options
context:
space:
mode:
authorGodfrey Chan <godfreykfc@gmail.com>2014-08-16 22:55:01 -0700
committerGodfrey Chan <godfreykfc@gmail.com>2014-08-16 23:09:10 -0700
commit008f3da3835e47f719ba6820703ba404ff363640 (patch)
treeb7d1a8154839de05eedb015e6d11e2b83c15e010 /activemodel
parent877ea784e4cd0d539bdfbd15839ae3d28169b156 (diff)
downloadrails-008f3da3835e47f719ba6820703ba404ff363640.tar.gz
rails-008f3da3835e47f719ba6820703ba404ff363640.tar.bz2
rails-008f3da3835e47f719ba6820703ba404ff363640.zip
Don't expose these new APIs yet (added in 877ea78 / #16189)
WARNING: don't use them! They might change or go away between future beta/RC/ patch releases! Also added a CHANGELOG entry for this.
Diffstat (limited to 'activemodel')
-rw-r--r--activemodel/lib/active_model/dirty.rb29
1 files changed, 15 insertions, 14 deletions
diff --git a/activemodel/lib/active_model/dirty.rb b/activemodel/lib/active_model/dirty.rb
index ed00d8cf12..ca04f48c1c 100644
--- a/activemodel/lib/active_model/dirty.rb
+++ b/activemodel/lib/active_model/dirty.rb
@@ -114,7 +114,7 @@ module ActiveModel
include ActiveModel::AttributeMethods
included do
- attribute_method_suffix '_changed?', '_change', '_will_change!', '_was', '_was='
+ attribute_method_suffix '_changed?', '_change', '_will_change!', '_was'
attribute_method_affix prefix: 'reset_', suffix: '!'
attribute_method_affix prefix: 'restore_', suffix: '!'
end
@@ -180,26 +180,13 @@ module ActiveModel
attribute_changed?(attr) ? changed_attributes[attr] : __send__(attr)
end
- # Handle <tt>*_was=</tt> for +method_missing+
- def attribute_was=(attr, old_value)
- attributes_changed_by_setter[attr] = old_value
- end
- alias_method :set_attribute_was, :attribute_was=
-
# Restore all previous data of the provided attributes.
def restore_attributes(attributes = changed)
attributes.each { |attr| restore_attribute! attr }
end
- # Remove changes information for the provided attributes.
- def clear_attribute_changes(attributes)
- attributes_changed_by_setter.except!(*attributes)
- end
-
private
- alias_method :attributes_changed_by_setter, :changed_attributes # :nodoc:
-
# Removes current changes and makes them accessible through +previous_changes+.
def changes_applied # :doc:
@previously_changed = changes
@@ -249,5 +236,19 @@ module ActiveModel
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