Class: ActiveModel::Validations::ExclusionValidator

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

Constant Summary

ERROR_MESSAGE =
"An object with the method #include? or a proc or lambda is required, " <<
"and must be supplied as the :in option of the configuration hash"

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

- (Object) check_validity!



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

def check_validity!
  unless [:include?, :call].any? { |method| options[:in].respond_to?(method) }
    raise ArgumentError, ERROR_MESSAGE
  end
end

- (Object) validate_each(record, attribute, value)



17
18
19
20
21
22
23
# File 'activemodel/lib/active_model/validations/exclusion.rb', line 17

def validate_each(record, attribute, value)
  delimiter = options[:in]
  exclusions = delimiter.respond_to?(:call) ? delimiter.call(record) : delimiter
  if exclusions.send(inclusion_method(exclusions), value)
    record.errors.add(attribute, :exclusion, options.except(:in).merge!(:value => value))
  end
end