Class: ActiveModel::Validations::ComparisonValidator
Do not use. This class is for internal use only.
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
|
|
Instance Chain:
|
|
Inherits: |
ActiveModel::EachValidator
|
Defined in: | activemodel/lib/active_model/validations/comparison.rb |
Constant Summary
Comparability
- Included
Class Method Summary
::ActiveModel::EachValidator
- Inherited
.new | Returns a new validator instance. |
::ActiveModel::Validator
- Inherited
Instance Attribute Summary
Instance Method Summary
ResolveValue
- Included
Comparability
- Included
::ActiveModel::EachValidator
- Inherited
#check_validity! | Hook method that gets called by the initializer allowing verification that the arguments supplied are valid. |
#validate | Performs validation on the supplied record. |
#validate_each | Override this method in subclasses with the validation logic, adding errors to the records #errors array where necessary. |
#prepare_value_for_validation |
::ActiveModel::Validator
- Inherited
Constructor Details
This class inherits a constructor from ActiveModel::EachValidator
Instance Method Details
#check_validity!
[ GitHub ]# File 'activemodel/lib/active_model/validations/comparison.rb', line 12
def check_validity! unless .keys.intersect?(COMPARE_CHECKS.keys) 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)
[ GitHub ]# File 'activemodel/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