Class: Attribool::Validators::MethodNameValidator
- Inherits:
- 
      Object
      
        - Object
- Attribool::Validators::MethodNameValidator
 
- Defined in:
- lib/attribool/validators/method_name_validator.rb
Overview
Ensures that if multiple attributes are being defined, and method_name is provided, that method_name is a Proc.
Instance Method Summary collapse
- 
  
    
      #error  ⇒ ArgumentError 
    
    
  
  
  
  
  
  
  
  
  
    The exception to raise if validations fail. 
- 
  
    
      #initialize(method_name, number_of_attributes)  ⇒ MethodNameValidator 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    Construct the validator. 
- 
  
    
      #valid?  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    Is there either one attribute, or is method_namenilor aProc?.
Constructor Details
#initialize(method_name, number_of_attributes) ⇒ MethodNameValidator
Construct the validator.
| 12 13 14 15 | # File 'lib/attribool/validators/method_name_validator.rb', line 12 def initialize(method_name, number_of_attributes) @method_name = method_name @number_of_attributes = number_of_attributes end | 
Instance Method Details
#error ⇒ ArgumentError
The exception to raise if validations fail.
| 27 28 29 | # File 'lib/attribool/validators/method_name_validator.rb', line 27 def error ArgumentError.new("Must use a Proc when creating multiple methods") end | 
#valid? ⇒ Boolean
Is there either one attribute, or is method_name nil or a Proc?
| 19 20 21 | # File 'lib/attribool/validators/method_name_validator.rb', line 19 def valid? @number_of_attributes == 1 || nil_or_proc? end |