Class: Attribool::Validators::NilAttributeValidator
- Inherits:
- 
      Object
      
        - Object
- Attribool::Validators::NilAttributeValidator
 
- Defined in:
- lib/attribool/validators/nil_attribute_validator.rb
Overview
Ensures that a value is not nil, unless nil is allowed as a value.
Instance Method Summary collapse
- 
  
    
      #error  ⇒ TypeError 
    
    
  
  
  
  
  
  
  
  
  
    The exception to raise if validations fail. 
- 
  
    
      #initialize(ivar, value, allow_nil)  ⇒ NilAttributeValidator 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    Construct the validator. 
- 
  
    
      #valid?  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    Do we either allow values to be nil, or is the value notnil?.
Constructor Details
#initialize(ivar, value, allow_nil) ⇒ NilAttributeValidator
Construct the validator.
| 15 16 17 18 19 | # File 'lib/attribool/validators/nil_attribute_validator.rb', line 15 def initialize(ivar, value, allow_nil) @ivar = ivar @value = value @allow_nil = allow_nil end | 
Instance Method Details
#error ⇒ TypeError
The exception to raise if validations fail.
| 33 34 35 | # File 'lib/attribool/validators/nil_attribute_validator.rb', line 33 def error TypeError.new("#{@ivar} is nil") end | 
#valid? ⇒ Boolean
Do we either allow values to be nil, or is the value not nil?
| 25 26 27 | # File 'lib/attribool/validators/nil_attribute_validator.rb', line 25 def valid? @allow_nil || !@value.nil? end |