Class: SmartCore::Types::Primitive::RuntimeAttributesChecker Private

Inherits:
Object
  • Object
show all
Defined in:
lib/smart_core/types/primitive/runtime_attributes_checker.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.3.0

Constant Summary collapse

ATTRIBUTES_IS_NOT_ALLOWED_CHECKER =

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

Returns:

  • (Proc)

Since:

  • 0.3.0

proc do |attrs|
  attrs.empty? || raise(SmartCore::Types::RuntimeAttriburtesUnsupportedError, <<~ERROR_MESSAGE)
    This type has no support for runtime attributes.
  ERROR_MESSAGE
end.freeze

Instance Method Summary collapse

Constructor Details

#initialize(attributes_checker) ⇒ 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:

  • attributes_checker (Proc)

Since:

  • 0.3.0



21
22
23
24
# File 'lib/smart_core/types/primitive/runtime_attributes_checker.rb', line 21

def initialize(attributes_checker)
  @type = nil
  @attributes_checker = attributes_checker || ATTRIBUTES_IS_NOT_ALLOWED_CHECKER
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.3.0



42
43
44
# File 'lib/smart_core/types/primitive/runtime_attributes_checker.rb', line 42

def ___assign_type___(type)
  @type = type
end

#___copy_for___(type) ⇒ SmartCore::Types::Primitive::RuntimeAttributesChecker

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.



31
32
33
34
35
# File 'lib/smart_core/types/primitive/runtime_attributes_checker.rb', line 31

def ___copy_for___(type)
  self.class.new(attributes_checker).tap do |instance_copy|
    instance_copy.___assign_type___(type)
  end
end

#check!(runtime_attributes) ⇒ 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:

  • runtime_attributes (Array<Any>)

Raises:

Since:

  • 0.3.0



53
54
55
56
57
58
59
60
61
62
# File 'lib/smart_core/types/primitive/runtime_attributes_checker.rb', line 53

def check!(runtime_attributes)
  unless !!attributes_checker.call(runtime_attributes)
    # TODO (0.x.0):
    #   Full type name (with type category; and delegated to the type object).
    #   (main problem: sum and mult types has no type name and type category)
    raise(SmartCore::Types::IncorrectRuntimeAttributesError, <<~ERROR_MESSAGE)
      Incorrect runtime attributes for #{type.name}.
    ERROR_MESSAGE
  end
end