Class: ActiveModel::Validations::ComparisonValidator
- Inherits:
-
EachValidator
- Object
- ActiveModel::Validator
- EachValidator
- ActiveModel::Validations::ComparisonValidator
- Includes:
- Comparability, ResolveValue
- Defined in:
- lib/active_model/validations/comparison.rb
Overview
:nodoc:
Constant Summary
Constants included from Comparability
ActiveModel::Validations::Comparability::COMPARE_CHECKS
Instance Attribute Summary
Attributes inherited from EachValidator
Attributes inherited from ActiveModel::Validator
Instance Method Summary collapse
Methods included from ResolveValue
Methods included from Comparability
Methods inherited from EachValidator
Methods inherited from ActiveModel::Validator
#initialize, kind, #kind, #validate
Constructor Details
This class inherits a constructor from ActiveModel::EachValidator
Instance Method Details
#check_validity! ⇒ Object
12 13 14 15 16 17 |
# File 'lib/active_model/validations/comparison.rb', line 12 def check_validity! unless (.keys & COMPARE_CHECKS.keys).any? raise ArgumentError, "Expected one of :greater_than, :greater_than_or_equal_to, "\ ":equal_to, :less_than, :less_than_or_equal_to, or :other_than option to be supplied." end end |
#validate_each(record, attr_name, value) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/active_model/validations/comparison.rb', line 19 def validate_each(record, attr_name, value) .slice(*COMPARE_CHECKS.keys).each do |option, raw_option_value| option_value = resolve_value(record, raw_option_value) if value.nil? || value.blank? return record.errors.add(attr_name, :blank, **(value, option_value)) end unless value.public_send(COMPARE_CHECKS[option], option_value) record.errors.add(attr_name, option, **(value, option_value)) end rescue ArgumentError => e record.errors.add(attr_name, e.) end end |