mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Split the options checks from read_attribute_for_validation
This commit is contained in:
parent
1dee4990cd
commit
720a60e68c
2 changed files with 6 additions and 10 deletions
|
@ -108,9 +108,7 @@ module ActiveModel
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def read_attribute_for_validation(record, attr_name)
|
def read_attribute_for_validation(record, attr_name, value)
|
||||||
value = super
|
|
||||||
|
|
||||||
return value if record_attribute_changed_in_place?(record, attr_name)
|
return value if record_attribute_changed_in_place?(record, attr_name)
|
||||||
|
|
||||||
came_from_user = :"#{attr_name}_came_from_user?"
|
came_from_user = :"#{attr_name}_came_from_user?"
|
||||||
|
|
|
@ -147,10 +147,10 @@ module ActiveModel
|
||||||
# override +validate_each+ with validation logic.
|
# override +validate_each+ with validation logic.
|
||||||
def validate(record)
|
def validate(record)
|
||||||
attributes.each do |attribute|
|
attributes.each do |attribute|
|
||||||
catch(:allowed) do
|
value = record.read_attribute_for_validation(attribute)
|
||||||
value = read_attribute_for_validation(record, attribute)
|
next if (value.nil? && options[:allow_nil]) || (value.blank? && options[:allow_blank])
|
||||||
validate_each(record, attribute, value)
|
value = read_attribute_for_validation(record, attribute, value)
|
||||||
end
|
validate_each(record, attribute, value)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -167,9 +167,7 @@ module ActiveModel
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def read_attribute_for_validation(record, attr_name)
|
def read_attribute_for_validation(record, attr_name, value)
|
||||||
value = record.read_attribute_for_validation(attr_name)
|
|
||||||
throw(:allowed) if (value.nil? && options[:allow_nil]) || (value.blank? && options[:allow_blank])
|
|
||||||
value
|
value
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue