Class: ActiveModelValidatesIntersectionOf::Validator

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

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object

Raises:

  • (ArgumentError)


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

def validate_each(record, attribute, value)
  delimiter = options[:in] || options[:within]
  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, :within).merge!(value: value))
  end
end