Class: ActiveModelValidatesIntersectionOf::Validator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/active_model_validates_intersection_of/inclusion_intersection_validator.rb

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object

Raises:

  • (ArgumentError)


3
4
5
6
7
8
9
# File 'lib/active_model_validates_intersection_of/inclusion_intersection_validator.rb', line 3

def validate_each(record, attribute, value)
  delimiter = options[:in]
  raise(ArgumentError, "An array must be supplied as the :in option of the configuration hash") unless delimiter.kind_of?(Array)
  if (value - delimiter).any?
    record.errors.add(attribute, :inclusion, options.except(:in).merge!(value: value))
  end
end