class Attribool::Validators::StrictBooleanValidator

Ensures that a value is a boolean, unless strictness isn’t enforced.

Public Class Methods

new(value, strict) click to toggle source

Construct the validator.

@param [Object] value

@param [Boolean] strict

# File lib/attribool/validators/strict_boolean_validator.rb, line 13
def initialize(value, strict)
  @value = value
  @strict = strict
end

Public Instance Methods

error() click to toggle source

The exception to raise if validations fail.

@return [ArgumentError] the exception with message

# File lib/attribool/validators/strict_boolean_validator.rb, line 30
def error
  ArgumentError.new("#{@value} is not a boolean")
end
valid?() click to toggle source

Is strict set to false, or is +@value+ a boolean?

@return [Boolean]

# File lib/attribool/validators/strict_boolean_validator.rb, line 22
def valid?
  !@strict || [TrueClass, FalseClass].include?(@value.class)
end