Class: ActiveModel::Validations::ExclusionValidator
- Inherits:
-
EachValidator
- Object
- ActiveModel::Validator
- EachValidator
- ActiveModel::Validations::ExclusionValidator
- Defined in:
- activemodel/lib/active_model/validations/exclusion.rb
Constant Summary collapse
- ERROR_MESSAGE =
"An object with the method #include? or a proc or lambda is required, " << "and must be supplied as the :in (or :within) option of the configuration hash"
Instance Attribute Summary
Attributes inherited from EachValidator
Attributes inherited from ActiveModel::Validator
Instance Method Summary collapse
Methods inherited from EachValidator
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
10 11 12 13 14 |
# File 'activemodel/lib/active_model/validations/exclusion.rb', line 10 def check_validity! unless [:include?, :call].any? { |method| delimiter.respond_to?(method) } raise ArgumentError, ERROR_MESSAGE end end |
#validate_each(record, attribute, value) ⇒ Object
16 17 18 19 20 21 |
# File 'activemodel/lib/active_model/validations/exclusion.rb', line 16 def validate_each(record, attribute, value) exclusions = delimiter.respond_to?(:call) ? delimiter.call(record) : delimiter if exclusions.send(inclusion_method(exclusions), value) record.errors.add(attribute, :exclusion, .except(:in, :within).merge!(:value => value)) end end |