Class: Swarm::BranchExpression

Inherits:
Expression show all
Defined in:
lib/swarm/expressions/branch_expression.rb

Defined Under Namespace

Classes: InvalidPositionError

Instance Attribute Summary

Attributes inherited from HiveDweller

#hive, #id

Instance Method Summary collapse

Methods inherited from Expression

#_apply, #_reply, #apply, #arguments, #branch_position, #command, #evaluator, inherited, #meets_conditions?, #node, #node_at_position, #parent, #replied?, #replied_at, #reply, #reply_to_parent, #root?, storage_type, #tree

Methods inherited from HiveDweller

#==, all, #attributes, #change_attribute, #changed?, create, define_getter, define_setter, #delete, each, fetch, ids, inherited, #initialize, many_to_one, #new?, new_from_storage, one_to_many, reify_from_hash, #reload!, #save, #set_attributes, set_columns, #storage, #storage_id, storage_id_for_key, storage_type, #to_hash

Constructor Details

This class inherits a constructor from Swarm::HiveDweller

Instance Method Details

#add_and_apply_child(at_position) ⇒ Object



16
17
18
19
# File 'lib/swarm/expressions/branch_expression.rb', line 16

def add_and_apply_child(at_position)
  new_child = add_child(at_position)
  new_child.apply
end

#add_child(at_position) ⇒ Object



21
22
23
24
25
26
27
28
# File 'lib/swarm/expressions/branch_expression.rb', line 21

def add_child(at_position)
  node = tree[at_position]
  raise InvalidPositionError unless node

  expression = create_child_expression(node: node, at_position: at_position)
  add_to_children(expression)
  expression
end

#create_child_expression(node:, at_position:) ⇒ Object



30
31
32
33
34
35
36
37
38
39
# File 'lib/swarm/expressions/branch_expression.rb', line 30

def create_child_expression(node:, at_position:)
  klass = Router.expression_class_for_node(node)
  klass.create(
    hive: hive,
    parent_id: id,
    position: position + [at_position],
    workitem: workitem,
    process_id: process_id
  )
end

#kick_off_children(at_positions) ⇒ Object



9
10
11
12
13
14
# File 'lib/swarm/expressions/branch_expression.rb', line 9

def kick_off_children(at_positions)
  at_positions.each do |at_position|
    add_and_apply_child(at_position)
  end
  save
end