mirror of https://github.com/rails/rails
Passing in a Hash instance as kwargs parameters requires the "double splat" prefix
This commit is contained in:
parent
ea791e53f9
commit
4645f2d34f
|
@ -168,7 +168,7 @@ module ActiveModel
|
|||
|
||||
# Dispatch target for <tt>*_changed?</tt> attribute methods.
|
||||
def attribute_changed?(attr_name, **options) # :nodoc:
|
||||
mutations_from_database.changed?(attr_name.to_s, options)
|
||||
mutations_from_database.changed?(attr_name.to_s, **options)
|
||||
end
|
||||
|
||||
# Dispatch target for <tt>*_was</tt> attribute methods.
|
||||
|
|
|
@ -76,7 +76,7 @@ module ActiveModel
|
|||
defaults << :"#{i18n_scope}.errors.messages.#{type}"
|
||||
|
||||
catch(:exception) do
|
||||
translation = I18n.translate(defaults.first, options.merge(default: defaults.drop(1), throw: true))
|
||||
translation = I18n.translate(defaults.first, **options.merge(default: defaults.drop(1), throw: true))
|
||||
return translation unless translation.nil?
|
||||
end unless options[:message]
|
||||
else
|
||||
|
@ -90,7 +90,7 @@ module ActiveModel
|
|||
defaults = options.delete(:message) if options[:message]
|
||||
options[:default] = defaults
|
||||
|
||||
I18n.translate(key, options)
|
||||
I18n.translate(key, **options)
|
||||
end
|
||||
|
||||
def initialize(base, attribute, type = :invalid, **options)
|
||||
|
|
|
@ -162,9 +162,9 @@ module ActiveModel
|
|||
# person.errors.where(:name, :too_short) # => all name errors being too short
|
||||
# person.errors.where(:name, :too_short, minimum: 2) # => all name errors being too short and minimum is 2
|
||||
def where(attribute, type = nil, **options)
|
||||
attribute, type, options = normalize_arguments(attribute, type, options)
|
||||
attribute, type, options = normalize_arguments(attribute, type, **options)
|
||||
@errors.select { |error|
|
||||
error.match?(attribute, type, options)
|
||||
error.match?(attribute, type, **options)
|
||||
}
|
||||
end
|
||||
|
||||
|
@ -188,8 +188,8 @@ module ActiveModel
|
|||
# person.errors.delete(:name) # => ["cannot be nil"]
|
||||
# person.errors[:name] # => []
|
||||
def delete(attribute, type = nil, **options)
|
||||
attribute, type, options = normalize_arguments(attribute, type, options)
|
||||
matches = where(attribute, type, options)
|
||||
attribute, type, options = normalize_arguments(attribute, type, **options)
|
||||
matches = where(attribute, type, **options)
|
||||
matches.each do |error|
|
||||
@errors.delete(error)
|
||||
end
|
||||
|
@ -373,7 +373,7 @@ module ActiveModel
|
|||
def add(attribute, type = :invalid, **options)
|
||||
error = Error.new(
|
||||
@base,
|
||||
*normalize_arguments(attribute, type, options)
|
||||
*normalize_arguments(attribute, type, **options)
|
||||
)
|
||||
|
||||
if exception = options[:strict]
|
||||
|
@ -403,11 +403,11 @@ module ActiveModel
|
|||
# person.errors.added? :name, :too_long # => false
|
||||
# person.errors.added? :name, "is too long" # => false
|
||||
def added?(attribute, type = :invalid, options = {})
|
||||
attribute, type, options = normalize_arguments(attribute, type, options)
|
||||
attribute, type, options = normalize_arguments(attribute, type, **options)
|
||||
|
||||
if type.is_a? Symbol
|
||||
@errors.any? { |error|
|
||||
error.strict_match?(attribute, type, options)
|
||||
error.strict_match?(attribute, type, **options)
|
||||
}
|
||||
else
|
||||
messages_for(attribute).include?(type)
|
||||
|
@ -538,7 +538,7 @@ module ActiveModel
|
|||
details.each { |attribute, errors|
|
||||
errors.each { |error|
|
||||
type = error.delete(:error)
|
||||
add(attribute, type, error)
|
||||
add(attribute, type, **error)
|
||||
}
|
||||
}
|
||||
end
|
||||
|
|
|
@ -203,7 +203,7 @@ module ActiveModel
|
|||
defaults << @human
|
||||
|
||||
options = { scope: [@klass.i18n_scope, :models], count: 1, default: defaults }.merge!(options.except(:default))
|
||||
I18n.translate(defaults.shift, options)
|
||||
I18n.translate(defaults.shift, **options)
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -64,7 +64,7 @@ module ActiveModel
|
|||
defaults << attribute.humanize
|
||||
|
||||
options[:default] = defaults
|
||||
I18n.translate(defaults.shift, options)
|
||||
I18n.translate(defaults.shift, **options)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -5,7 +5,7 @@ module ActiveModel
|
|||
# == \Active \Model Absence Validator
|
||||
class AbsenceValidator < EachValidator #:nodoc:
|
||||
def validate_each(record, attr_name, value)
|
||||
record.errors.add(attr_name, :present, options) if value.present?
|
||||
record.errors.add(attr_name, :present, **options) if value.present?
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ module ActiveModel
|
|||
|
||||
def validate_each(record, attribute, value)
|
||||
unless acceptable_option?(value)
|
||||
record.errors.add(attribute, :accepted, options.except(:accept, :allow_nil))
|
||||
record.errors.add(attribute, :accepted, **options.except(:accept, :allow_nil))
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ module ActiveModel
|
|||
unless (confirmed = record.send("#{attribute}_confirmation")).nil?
|
||||
unless confirmation_value_equal?(record, attribute, value, confirmed)
|
||||
human_attribute_name = record.class.human_attribute_name(attribute)
|
||||
record.errors.add(:"#{attribute}_confirmation", :confirmation, options.except(:case_sensitive).merge!(attribute: human_attribute_name))
|
||||
record.errors.add(:"#{attribute}_confirmation", :confirmation, **options.except(:case_sensitive).merge!(attribute: human_attribute_name))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -9,7 +9,7 @@ module ActiveModel
|
|||
|
||||
def validate_each(record, attribute, value)
|
||||
if include?(record, value)
|
||||
record.errors.add(attribute, :exclusion, options.except(:in, :within).merge!(value: value))
|
||||
record.errors.add(attribute, :exclusion, **options.except(:in, :within).merge!(value: value))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -29,7 +29,7 @@ module ActiveModel
|
|||
end
|
||||
|
||||
def record_error(record, attribute, name, value)
|
||||
record.errors.add(attribute, :invalid, options.except(name).merge!(value: value))
|
||||
record.errors.add(attribute, :invalid, **options.except(name).merge!(value: value))
|
||||
end
|
||||
|
||||
def check_options_validity(name)
|
||||
|
|
|
@ -9,7 +9,7 @@ module ActiveModel
|
|||
|
||||
def validate_each(record, attribute, value)
|
||||
unless include?(record, value)
|
||||
record.errors.add(attribute, :inclusion, options.except(:in, :within).merge!(value: value))
|
||||
record.errors.add(attribute, :inclusion, **options.except(:in, :within).merge!(value: value))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -59,7 +59,7 @@ module ActiveModel
|
|||
default_message = options[MESSAGES[key]]
|
||||
errors_options[:message] ||= default_message if default_message
|
||||
|
||||
record.errors.add(attribute, MESSAGES[key], errors_options)
|
||||
record.errors.add(attribute, MESSAGES[key], **errors_options)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -44,12 +44,12 @@ module ActiveModel
|
|||
end
|
||||
|
||||
unless is_number?(raw_value)
|
||||
record.errors.add(attr_name, :not_a_number, filtered_options(raw_value))
|
||||
record.errors.add(attr_name, :not_a_number, **filtered_options(raw_value))
|
||||
return
|
||||
end
|
||||
|
||||
if allow_only_integer?(record) && !is_integer?(raw_value)
|
||||
record.errors.add(attr_name, :not_an_integer, filtered_options(raw_value))
|
||||
record.errors.add(attr_name, :not_an_integer, **filtered_options(raw_value))
|
||||
return
|
||||
end
|
||||
|
||||
|
@ -59,7 +59,7 @@ module ActiveModel
|
|||
case option
|
||||
when :odd, :even
|
||||
unless value.to_i.send(CHECKS[option])
|
||||
record.errors.add(attr_name, option, filtered_options(value))
|
||||
record.errors.add(attr_name, option, **filtered_options(value))
|
||||
end
|
||||
else
|
||||
case option_value
|
||||
|
@ -72,7 +72,7 @@ module ActiveModel
|
|||
option_value = parse_as_number(option_value)
|
||||
|
||||
unless value.send(CHECKS[option], option_value)
|
||||
record.errors.add(attr_name, option, filtered_options(value).merge!(count: option_value))
|
||||
record.errors.add(attr_name, option, **filtered_options(value).merge!(count: option_value))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,7 +4,7 @@ module ActiveModel
|
|||
module Validations
|
||||
class PresenceValidator < EachValidator # :nodoc:
|
||||
def validate_each(record, attr_name, value)
|
||||
record.errors.add(attr_name, :blank, options) if value.blank?
|
||||
record.errors.add(attr_name, :blank, **options) if value.blank?
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue