Class: Codeclimate::Collectors::Validations::TypeValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/codeclimate/collectors/validations/type_validator.rb

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attr_name, value) ⇒ Object



5
6
7
8
9
10
# File 'lib/codeclimate/collectors/validations/type_validator.rb', line 5

def validate_each(record, attr_name, value)
  type = options.fetch(:type)
  if !value.nil? && !value.is_a?(type)
    record.errors.add(attr_name, "must be a #{type}")
  end
end