Class: ActiveModel::Validations::FormatValidator
- Inherits:
-
EachValidator
- Object
- ActiveModel::Validator
- EachValidator
- ActiveModel::Validations::FormatValidator
- Includes:
- ResolveValue
- Defined in:
- lib/active_model/validations/format.rb
Overview
:nodoc:
Instance Attribute Summary
Attributes inherited from EachValidator
Attributes inherited from ActiveModel::Validator
Instance Method Summary collapse
Methods included from ResolveValue
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
20 21 22 23 24 25 26 27 |
# File 'lib/active_model/validations/format.rb', line 20 def check_validity! unless .include?(:with) ^ .include?(:without) # ^ == xor, or "exclusive or" raise ArgumentError, "Either :with or :without must be supplied (but not both)" end :with :without end |
#validate_each(record, attribute, value) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/active_model/validations/format.rb', line 10 def validate_each(record, attribute, value) if [:with] regexp = resolve_value(record, [:with]) record_error(record, attribute, :with, value) unless regexp.match?(value.to_s) elsif [:without] regexp = resolve_value(record, [:without]) record_error(record, attribute, :without, value) if regexp.match?(value.to_s) end end |