Class: ActiveModel::Validations::LessOrGreaterThanValidator
- Inherits:
-
EachValidator
- Object
- EachValidator
- ActiveModel::Validations::LessOrGreaterThanValidator
show all
- Defined in:
- lib/activemodel-validators/less_or_greater_than_validator.rb
Instance Method Summary
collapse
Instance Method Details
#check_validity! ⇒ Object
4
5
6
7
8
9
10
11
12
13
|
# File 'lib/activemodel-validators/less_or_greater_than_validator.rb', line 4
def check_validity!
unless options[:attr] or options[:value]
raise ArgumentError, "must supply :attr or :value option"
end
unless allowed_operators.include?(operator)
raise ArgumentError, ":operator must be one of #{allowed_operators.join(', ')} but was #{operator}"
end
end
|
#validate_each(record, attribute, value) ⇒ Object
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/activemodel-validators/less_or_greater_than_validator.rb', line 57
def validate_each(record, attribute, value)
@record = record
return if value.blank? or other_value.blank?
unless value.send(operator, other_value)
record.errors.add(attribute, message_key,
options.merge(
value: value,
operator: operator,
operator_text: operator_text,
attr_name: options[:attr],
other_value: other_value,
)
)
end
end
|