Class: DataValidator::InclusionValidator
- Inherits:
-
BaseValidator
- Object
- BaseValidator
- DataValidator::InclusionValidator
- Defined in:
- lib/validations/inclusion.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 option of the configuration hash'
Instance Attribute Summary
Attributes inherited from BaseValidator
#errors, #name, #options, #value
Instance Method Summary collapse
Methods inherited from BaseValidator
Constructor Details
This class inherits a constructor from DataValidator::BaseValidator
Instance Method Details
#check_validity! ⇒ Object
8 9 10 11 12 |
# File 'lib/validations/inclusion.rb', line 8 def check_validity! unless [:include?, :call].any?{ |method| [:in].respond_to?(method) } raise ArgumentError, ERROR_MESSAGE end end |
#validate ⇒ Object
14 15 16 17 18 19 |
# File 'lib/validations/inclusion.rb', line 14 def validate delimiter = [:in] unless delimiter.send(inclusion_method(delimiter), value) add_error :inclusion, value: value end end |