class Attribool::Validators::NilAttributeValidator
Ensures that a value is not nil
, unless nil
is allowed as a value.
Public Class Methods
new(ivar, value, allow_nil)
click to toggle source
Construct the validator.
@param [String, Symbol] ivar
@param [Object] value
@param [Boolean] allow_nil
# 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
Public Instance Methods
error()
click to toggle source
The exception to raise if validations fail.
@return [TypeError] the exception with message
# File lib/attribool/validators/nil_attribute_validator.rb, line 33 def error TypeError.new("#{@ivar} is nil") end
valid?()
click to toggle source
Do we either allow values to be nil
, or is the value not nil
?
@return [Boolean]
# File lib/attribool/validators/nil_attribute_validator.rb, line 25 def valid? @allow_nil || !@value.nil? end