class TypeValidator
Public Instance Methods
validate_each(record, attribute, value)
click to toggle source
# File lib/active_validation/validators/type_validator.rb, line 9 def validate_each(record, attribute, value) return if valid?(value, options) record.errors[attribute] << (options[:message] || I18n.t('active_validation.errors.messages.type')) end
Private Instance Methods
valid?(value, options)
click to toggle source
# File lib/active_validation/validators/type_validator.rb, line 18 def valid?(value, options) klass = options[:with] if klass == Boolean value.is_a?(TrueClass) || value.is_a?(FalseClass) else value.is_a?(klass) end end