Sha256: 4b6653c11cdf20cc611a892a6cc6c6fa6d93ce676a3171c2d6f162da9e05d0ff
Contents?: true
Size: 499 Bytes
Versions: 2
Compression:
Stored size: 499 Bytes
Contents
require 'active_model_validators_ex/array_validator_base' class ArrayFormatValidator < ArrayValidatorBase def initialize(options) unless options.key?(:with) and options[:with].is_a?(Regexp) raise 'options must contain a key :with, where the value is a Regexp' end super(options) end def custom_validations(record, attribute, value) unless value.all? { |val| !val.match(options[:with]).nil? } record.errors.add(attribute, :array_format, options) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
active_model_validators_ex-1.0.0 | lib/active_model_validators_ex/array_format_validator.rb |
active_model_validators_ex-0.3.2 | lib/active_model_validators_ex/array_format_validator.rb |