class TypeValidator
Public Instance Methods
options()
click to toggle source
Calls superclass method
# File lib/type_validator.rb, line 4 def options super.merge(allow_nil: true) end
validate_each(record, attribute, value)
click to toggle source
# File lib/type_validator.rb, line 8 def validate_each(record, attribute, value) classes = options[:in] || [options[:with]] if classes.all? { |klass| !value.is_a?(klass) } record.errors.add(attribute, "must be a #{classes.join(' or ')}, not a #{value.class}") end end