4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/activemodel-validators/date_validator.rb', line 4
def validate_each(record, attr_name, value)
before_type_cast = "#{attr_name}_before_type_cast"
raw_value = record.send(before_type_cast) if record.respond_to?(before_type_cast.to_sym)
raw_value ||= value
if raw_value.present? and !value.is_a?(Date)
record.errors.add attr_name, :date_invalid,
expected_format: expected_format
return end
if options[:required] && value.blank?
message = (options[:required] == true ? :blank : options[:required])
record.errors.add attr_name, message
end
end
|