Class: SmartCore::Types::Primitive::NilableValidator Private

Inherits:
Object
  • Object
show all
Defined in:
lib/smart_core/types/primitive/nilable_validator.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Since:

  • 0.2.0

Defined Under Namespace

Classes: Result

Instance Method Summary collapse

Constructor Details

#initialize(validator) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

]

Parameters:

Since:

  • 0.2.0



18
19
20
21
# File 'lib/smart_core/types/primitive/nilable_validator.rb', line 18

def initialize(validator)
  @type = nil
  @validator = validator
end

Instance Method Details

#___assign_type___(type) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Parameters:

Since:

  • 0.2.0



28
29
30
# File 'lib/smart_core/types/primitive/nilable_validator.rb', line 28

def ___assign_type___(type)
  @type = type
end

#valid?(value) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)

Since:

  • 0.2.0



36
37
38
# File 'lib/smart_core/types/primitive/nilable_validator.rb', line 36

def valid?(value)
  value == nil ? true : validator.valid?(value)
end

#validate(value) ⇒ SmartCore::Types::Primitive::Validator::Result, ...

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



48
49
50
51
# File 'lib/smart_core/types/primitive/nilable_validator.rb', line 48

def validate(value)
  return Result.new(type, value) if value == nil
  validator.validate(value)
end

#validate!(value) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Parameters:

  • value (Any)

Raises:

Since:

  • 0.2.0



60
61
62
63
# File 'lib/smart_core/types/primitive/nilable_validator.rb', line 60

def validate!(value)
  return if valid?(value)
  raise(SmartCore::Types::TypeError, 'Invalid type')
end