Class: TypeValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/validator/type_validator.rb

Instance Method Summary collapse

Instance Method Details

#optionsObject



4
5
6
# File 'lib/validator/type_validator.rb', line 4

def options
  super.merge(allow_nil: true)
end

#validate_each(record, attribute, value) ⇒ Object



8
9
10
11
12
# File 'lib/validator/type_validator.rb', line 8

def validate_each(record, attribute, value)
  unless value.is_a?(options[:with])
    record.errors.add(attribute, "must be a #{options[:with]}, not #{value.class}")
  end
end