Class: ArrayFormatValidator
- Inherits:
-
ArrayValidatorBase
- Object
- ActiveModel::EachValidator
- ArrayValidatorBase
- ArrayFormatValidator
- Defined in:
- lib/active_model_validators_ex/array_format_validator.rb
Instance Method Summary collapse
- #custom_validations(record, attribute, value) ⇒ Object
-
#initialize(options) ⇒ ArrayFormatValidator
constructor
A new instance of ArrayFormatValidator.
Methods inherited from ArrayValidatorBase
Constructor Details
#initialize(options) ⇒ ArrayFormatValidator
Returns a new instance of ArrayFormatValidator.
4 5 6 7 8 9 10 |
# File 'lib/active_model_validators_ex/array_format_validator.rb', line 4 def initialize() unless .key?(:with) and [:with].is_a?(Regexp) raise 'options must contain a key :with, where the value is a Regexp' end super() end |
Instance Method Details
#custom_validations(record, attribute, value) ⇒ Object
12 13 14 15 16 |
# File 'lib/active_model_validators_ex/array_format_validator.rb', line 12 def custom_validations(record, attribute, value) unless value.all? { |val| !val.match([:with]).nil? } record.errors.add(attribute, :array_format, ) end end |