Class: Attribool::Validators::StrictBooleanValidator
- Inherits:
- 
      Object
      
        - Object
- Attribool::Validators::StrictBooleanValidator
 
- Defined in:
- lib/attribool/validators/strict_boolean_validator.rb
Overview
Ensures that a value is a boolean, unless strictness isn’t enforced.
Instance Method Summary collapse
- 
  
    
      #error  ⇒ ArgumentError 
    
    
  
  
  
  
  
  
  
  
  
    The exception to raise if validations fail. 
- 
  
    
      #initialize(value, strict)  ⇒ StrictBooleanValidator 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    Construct the validator. 
- 
  
    
      #valid?  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    Is strictset tofalse, or is @value a boolean?.
Constructor Details
#initialize(value, strict) ⇒ StrictBooleanValidator
Construct the validator.
| 13 14 15 16 | # File 'lib/attribool/validators/strict_boolean_validator.rb', line 13 def initialize(value, strict) @value = value @strict = strict end | 
Instance Method Details
#error ⇒ ArgumentError
The exception to raise if validations fail.
| 30 31 32 | # File 'lib/attribool/validators/strict_boolean_validator.rb', line 30 def error ArgumentError.new("#{@value} is not a boolean") end | 
#valid? ⇒ Boolean
Is strict set to false, or is @value a boolean?
| 22 23 24 | # File 'lib/attribool/validators/strict_boolean_validator.rb', line 22 def valid? !@strict || [TrueClass, FalseClass].include?(@value.class) end |