class TypeValidator
Public Instance Methods
klasses()
click to toggle source
# File lib/validator/type_validator.rb, line 8 def klasses options[:in] || [options[:with]] end
options()
click to toggle source
Calls superclass method
# File lib/validator/type_validator.rb, line 4 def options super.merge(allow_nil: true) end
validate_each(record, attribute, value)
click to toggle source
# 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