JamesBrooks/hash_validator

View on GitHub
lib/hash_validator/validators/boolean_validator.rb

Summary

Maintainability
A
0 mins
Test Coverage
class HashValidator::Validator::BooleanValidator < HashValidator::Validator::Base
  def initialize
    super('boolean')  # The name of the validator
  end

  def validate(key, value, _validations, errors)
    unless [TrueClass, FalseClass].include?(value.class)
      errors[key] = presence_error_message
    end
  end
end

HashValidator.append_validator(HashValidator::Validator::BooleanValidator.new)