Class: HashValidator::Validator::BooleanValidator

Inherits:
Base
  • Object
show all
Defined in:
lib/hash_validator/validators/boolean_validator.rb

Instance Attribute Summary

Attributes inherited from Base

#name

Instance Method Summary collapse

Methods inherited from Base

#presence_error_message, #should_validate?

Constructor Details

#initializeBooleanValidator

Returns a new instance of BooleanValidator.



2
3
4
# File 'lib/hash_validator/validators/boolean_validator.rb', line 2

def initialize
  super('boolean')  # The name of the validator
end

Instance Method Details

#validate(key, value, _validations, errors) ⇒ Object



6
7
8
9
10
# File 'lib/hash_validator/validators/boolean_validator.rb', line 6

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