Sha256: fbc88df0ca750ab11a148184c13811007f8b9b8782baa23e6e2d8547ae162b48

Contents?: true

Size: 514 Bytes

Versions: 1

Compression:

Stored size: 514 Bytes

Contents

class Boolean
  # Implement pseudo-boolean class
end

class TypeValidator < ActiveModel::EachValidator

  def validate_each(record, attribute, value)
    unless valid?(value, options)
      record.errors[attribute] <<
        (options[:message] || I18n.t('active_validation.errors.messages.type'))
    end
  end

  private

  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

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
active_validation-4.0.0 lib/active_validation/validators/type_validator.rb