Class: ActiveModel::Validations::InclusionValidator

Inherits:
EachValidator show all
Defined in:
activemodel/lib/active_model/validations/inclusion.rb

Instance Attribute Summary

Attributes inherited from EachValidator

#attributes

Attributes inherited from ActiveModel::Validator

#options

Instance Method Summary collapse

Methods inherited from EachValidator

#initialize, #validate

Methods inherited from ActiveModel::Validator

#initialize, kind, #kind, #validate

Constructor Details

This class inherits a constructor from ActiveModel::EachValidator

Instance Method Details

#check_validity!Object

Raises:

  • (ArgumentError)


6
7
8
9
# File 'activemodel/lib/active_model/validations/inclusion.rb', line 6

def check_validity!
   raise ArgumentError, "An object with the method include? is required must be supplied as the " <<
                        ":in option of the configuration hash" unless options[:in].respond_to?(:include?)
end

#validate_each(record, attribute, value) ⇒ Object



11
12
13
14
15
# File 'activemodel/lib/active_model/validations/inclusion.rb', line 11

def validate_each(record, attribute, value)
  unless options[:in].include?(value)
    record.errors.add(attribute, :inclusion, options.except(:in).merge!(:value => value))
  end
end