5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/sexy_validations/validators/date.rb', line 5
def self.validate(record, attribute, value, options)
return unless value
if value.is_a?(::Date) || value.is_a?(::Time)
if options.is_a?(Hash)
min = options[:within].min
if value < min
record.errors.add(attribute, "zu früh (frühestens #{min})")
end
max = options[:within].max
if value > max
record.errors.add(attribute, "zu spät (spätestens #{max})")
end
end
else
record.errors.add(attribute, "ungültig")
end
end
|