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
|
||||
|
||||
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?"
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue