aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel
diff options
context:
space:
mode:
authorJeremy Daer <jeremydaer@gmail.com>2016-04-13 11:09:31 -0700
committerJeremy Daer <jeremydaer@gmail.com>2016-04-13 11:09:31 -0700
commite25d7a78b517e90608b0d1d03a44c78bec400fa7 (patch)
tree10b5e357a8b6ef51340f4d47a872205371910662 /activemodel
parentefaa6e4f79d457c2cdd08cbc56d63bc972a6993c (diff)
parentafb1f32e7994ed0ba1163672343e3dd59a845d42 (diff)
downloadrails-e25d7a78b517e90608b0d1d03a44c78bec400fa7.tar.gz
rails-e25d7a78b517e90608b0d1d03a44c78bec400fa7.tar.bz2
rails-e25d7a78b517e90608b0d1d03a44c78bec400fa7.zip
Merge pull request #24519 from bogdan/diry-keyword-args
Switch to keyword args for attribute_changed?
Diffstat (limited to 'activemodel')
-rw-r--r--activemodel/lib/active_model/dirty.rb16
1 files changed, 8 insertions, 8 deletions
diff --git a/activemodel/lib/active_model/dirty.rb b/activemodel/lib/active_model/dirty.rb
index 9aca5f2c90..38c0ab6c32 100644
--- a/activemodel/lib/active_model/dirty.rb
+++ b/activemodel/lib/active_model/dirty.rb
@@ -119,6 +119,9 @@ module ActiveModel
extend ActiveSupport::Concern
include ActiveModel::AttributeMethods
+ OPTION_NOT_GIVEN = Object.new # :nodoc:
+ private_constant :OPTION_NOT_GIVEN
+
included do
attribute_method_suffix '_changed?', '_change', '_will_change!', '_was'
attribute_method_suffix '_previously_changed?', '_previous_change'
@@ -174,13 +177,10 @@ module ActiveModel
end
# Handles <tt>*_changed?</tt> for +method_missing+.
- def attribute_changed?(attr, options = nil) #:nodoc:
- result = changes_include?(attr)
- if options
- result &&= options[:to] == __send__(attr) if options.key?(:to)
- result &&= options[:from] == changed_attributes[attr] if options.key?(:from)
- end
- !!result
+ def attribute_changed?(attr, from: OPTION_NOT_GIVEN, to: OPTION_NOT_GIVEN) # :nodoc:
+ changes_include?(attr) &&
+ (to == OPTION_NOT_GIVEN || to == __send__(attr)) &&
+ (from == OPTION_NOT_GIVEN || from == changed_attributes[attr])
end
# Handles <tt>*_was</tt> for +method_missing+.
@@ -189,7 +189,7 @@ module ActiveModel
end
# Handles <tt>*_previously_changed?</tt> for +method_missing+.
- def attribute_previously_changed?(attr, options = {}) #:nodoc:
+ def attribute_previously_changed?(attr) #:nodoc:
previous_changes_include?(attr)
end