Class: Poncho::Validations::FormatValidator
- Inherits:
-
EachValidator
- Object
- Poncho::Validator
- EachValidator
- Poncho::Validations::FormatValidator
- Defined in:
- lib/poncho/validations/format.rb
Instance Attribute Summary
Attributes inherited from EachValidator
Attributes inherited from Poncho::Validator
Instance Method Summary collapse
Methods inherited from EachValidator
Methods inherited from Poncho::Validator
#initialize, kind, #kind, #validate
Constructor Details
This class inherits a constructor from Poncho::EachValidator
Instance Method Details
#check_validity! ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/poncho/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 (, :with) (, :without) end |
#validate_each(record, attribute, value) ⇒ Object
4 5 6 7 8 9 10 11 12 |
# File 'lib/poncho/validations/format.rb', line 4 def validate_each(record, attribute, value) if [:with] regexp = option_call(record, :with) record_error(record, attribute, :with, value) if value.to_s !~ regexp elsif [:without] regexp = option_call(record, :without) record_error(record, attribute, :without, value) if value.to_s =~ regexp end end |