class Attribool::Validators::ConditionValidator

Ensures that a condition is either nil or a Proc.

Public Class Methods

new(condition) click to toggle source

Construct the validator.

@param [nil, Proc] condition

# File lib/attribool/validators/condition_validator.rb, line 11
def initialize(condition)
  @condition = condition
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/condition_validator.rb, line 27
def error
  ArgumentError.new("Condition is not a proc")
end
valid?() click to toggle source

Is the condition either nil or a Proc?

@return [Boolean]

# File lib/attribool/validators/condition_validator.rb, line 19
def valid?
  @condition.nil? || @condition.is_a?(Proc)
end