mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Use keyword arguments to cleanup without droping performance
This commit is contained in:
parent
ba194d4230
commit
afb1f32e79
1 changed files with 8 additions and 8 deletions
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue