Class: Drymm::Shapes::Node Abstract

Inherits:
Dry::Struct
  • Object
show all
Extended by:
Dry::Tuple::StructClassInterface
Includes:
Dry::Core::Constants, ASTMethods, JSONMethods
Defined in:
lib/drymm/shapes/node.rb

Overview

This class is abstract.

Dry::Struct abstract subclass, extended with Dry::Tuple::StructClassInterface

Direct Known Subclasses

Const, Fn::FnNode, Logic::Rule, Types::Type

Class Method Summary collapse

Methods included from ASTMethods

#compile, #to_ast

Methods included from JSONMethods

#to_json

Class Method Details

.type_enum(*input) ⇒ Dry::Types[Enum<Symbol>]

Shorthand to declare type as a enum

Parameters:

  • input (Array<Symbol>)

Returns:



53
54
55
# File 'lib/drymm/shapes/node.rb', line 53

def type_enum(*input)
  type_identifier(input)
end

.type_identifier(klass) ⇒ Dry::Types::Type .type_identifier(name) ⇒ Dry::Types::Type .type_identifier(list) ⇒ Dry::Types::Type

Note:

To hook the assigned type identifier for specific subclass, just override this method.

Returns coercible symbol type with specific value — node type identifier (declared, for example, as ‘type` in Drymm::Shape::LogicNode.inherited).

Examples:

Hook the type value

class Something < Drymm::S::Node
  def self.type_identifier(*)
    super(:hooked)
  end
end

Overloads:

  • .type_identifier(klass) ⇒ Dry::Types::Type

    Generates identifier from the given class name

    Parameters:

    • klass (Class)
  • .type_identifier(name) ⇒ Dry::Types::Type

    Coerces the given name to symbol and uses it as a node type identifier

    Parameters:

    • name (#to_sym)
  • .type_identifier(list) ⇒ Dry::Types::Type

    Builds Dry::Types::Enum from the given list of values

    Parameters:

    • list (Array)

Returns:

  • (Dry::Types::Type)

    coercible symbol type with specific value — node type identifier (declared, for example, as ‘type` in Drymm::Shape::LogicNode.inherited)



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/drymm/shapes/node.rb', line 37

def type_identifier(input = self)
  case input
  when ::String, ::Symbol
    Drymm["types.sym"].constrained(eql: input.to_sym)
  when ::Array
    Drymm["types.sym"].enum(*input)
  when ::Module
    type_identifier(Drymm["fn.type_identifier"][input.name])
  else
    raise ArgumentError
  end
end