Module: Drymm::Shapes::Branch

Included in:
Logic::Rule, Types::Type
Defined in:
lib/drymm/shapes/branch.rb

Overview

Drymm::Shapes‘s class interface mixin, designed to extend an abstract __subclass__ of Node, creating a kind of Shape’s branch or, in other words, derivative, to enclose specific namespace.

Instance Method Summary collapse

Instance Method Details

#auto_tuple(*keys) ⇒ Object

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.



24
25
26
27
28
29
30
31
32
33
# File 'lib/drymm/shapes/branch.rb', line 24

def auto_tuple(*keys)
  keys_order(keys_order | keys)
  index = schema.keys.map { |t| [t.name, t.type] }.to_h
  key_type, *node_types = index.values_at(*keys_order)
  if tuple_right
    tuple Tuple(key_type, Tuple(*node_types))
  else
    tuple Tuple(key_type, *node_types)
  end
end

#auto_tuple!(*keys) ⇒ Object



39
40
41
42
43
44
# File 'lib/drymm/shapes/branch.rb', line 39

def auto_tuple!(*keys)
  remove_instance_variable(:@keys_order) if instance_variable_defined?(:@keys_order)
  remove_instance_variable(:@tuple) if instance_variable_defined?(:@tuple)
  keys_order []
  auto_tuple(*keys)
end

#coerce_tuple(input) ⇒ Object

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.

Flattens the 1st level of the input array.



19
20
21
# File 'lib/drymm/shapes/branch.rb', line 19

def coerce_tuple(input)
  super(input.flatten(1))
end

#retupleObject



35
36
37
# File 'lib/drymm/shapes/branch.rb', line 35

def retuple
  auto_tuple!(*keys_order)
end