12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/can_has_validations/validators/ordering_validator.rb', line 12
def validate_each(record, attribute, value)
compare_to = Array.wrap(options[:value_of] || options[:values_of] || options[:in] || options[:with])
compare_to.each do |attr_name|
greater = attr_name.call(record) if attr_name.respond_to?(:call)
greater ||= Time.now if attr_name==:now && !record.respond_to?(:now)
greater ||= record.send attr_name
next unless value && greater
unless value < greater
attr2 = attr_name.respond_to?(:call) ? 'it is' : record.class.human_attribute_name(attr_name)
record.errors.add(attribute, :before, value:, attribute2: attr2, before_value: greater, **options.except(:before))
end
end
end
|