Class: TypeValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- TypeValidator
- Defined in:
- lib/validator/type_validator.rb
Instance Method Summary collapse
Instance Method Details
#klasses ⇒ Object
8 9 10 |
# File 'lib/validator/type_validator.rb', line 8 def klasses [:in] || [[:with]] end |
#options ⇒ Object
4 5 6 |
# File 'lib/validator/type_validator.rb', line 4 def super.merge(allow_nil: true) end |
#validate_each(record, attribute, value) ⇒ Object
12 13 14 15 16 |
# File 'lib/validator/type_validator.rb', line 12 def validate_each(record, attribute, value) unless klasses.any? { |klass| value.is_a?(klass) } record.errors.add(attribute, "must be a #{klasses}, not #{value.class}") end end |