1
0
Fork 0
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:
Ryuta Kamizono 2020-12-09 16:43:26 +09:00
parent 1dee4990cd
commit 720a60e68c
2 changed files with 6 additions and 10 deletions

View file

@ -108,9 +108,7 @@ module ActiveModel
end
end
def read_attribute_for_validation(record, attr_name)
value = super
def read_attribute_for_validation(record, attr_name, value)
return value if record_attribute_changed_in_place?(record, attr_name)
came_from_user = :"#{attr_name}_came_from_user?"

View file

@ -147,10 +147,10 @@ module ActiveModel
# override +validate_each+ with validation logic.
def validate(record)
attributes.each do |attribute|
catch(:allowed) do
value = read_attribute_for_validation(record, attribute)
validate_each(record, attribute, value)
end
value = record.read_attribute_for_validation(attribute)
next if (value.nil? && options[:allow_nil]) || (value.blank? && options[:allow_blank])
value = read_attribute_for_validation(record, attribute, value)
validate_each(record, attribute, value)
end
end
@ -167,9 +167,7 @@ module ActiveModel
end
private
def read_attribute_for_validation(record, attr_name)
value = record.read_attribute_for_validation(attr_name)
throw(:allowed) if (value.nil? && options[:allow_nil]) || (value.blank? && options[:allow_blank])
def read_attribute_for_validation(record, attr_name, value)
value
end
end