15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/common_lib/active_model/validations/past_date.rb', line 15
def validate(record)
[attributes].flatten.each do |attribute|
value = record.send(:read_attribute_for_validation, attribute)
allow_today = ( options.has_key?(:allow_today) ) ? options[:allow_today] : true
base_date = if value.is_a?(ActiveSupport::TimeWithZone)
( allow_today ) ? Time.zone.now : ( Time.zone.now - 1.day )
elsif value.is_a?(DateTime)
( allow_today ) ? Time.now : ( Time.now - 1.day )
else
( allow_today ) ? Date.current : Date.yesterday
end
if !value.blank? && value > base_date
record.errors.add(attribute, :future_date, options)
end
end
end
|