Class: ActiveModel::Validations::FormatValidator
- Inherits:
-
EachValidator
- Object
- ActiveModel::Validator
- EachValidator
- ActiveModel::Validations::FormatValidator
- Defined in:
- lib/active_model/validations/format.rb
Instance Attribute Summary
Attributes inherited from EachValidator
Attributes inherited from ActiveModel::Validator
Instance Method Summary collapse
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
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/active_model/validations/format.rb', line 14 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 if [:with] && ![:with].is_a?(Regexp) raise ArgumentError, "A regular expression must be supplied as the :with option of the configuration hash" end if [:without] && ![:without].is_a?(Regexp) raise ArgumentError, "A regular expression must be supplied as the :without option of the configuration hash" end end |
#validate_each(record, attribute, value) ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/active_model/validations/format.rb', line 6 def validate_each(record, attribute, value) if [:with] && value.to_s !~ [:with] record.errors.add(attribute, :invalid, .except(:with).merge!(:value => value)) elsif [:without] && value.to_s =~ [:without] record.errors.add(attribute, :invalid, .except(:without).merge!(:value => value)) end end |