Class: SpotFlow::Bpmn::Gateway

Inherits:
Step show all
Defined in:
lib/spot_flow/bpmn/gateway.rb

Instance Attribute Summary

Attributes inherited from Step

#default, #default_ref, #incoming, #outgoing

Attributes inherited from Element

#extension_elements, #id, #name

Instance Method Summary collapse

Methods inherited from Step

#converging?, #diverging?, #initialize, #input_mappings, #leave, #outgoing_flows, #output_mappings

Methods inherited from Element

#initialize, #inspect

Constructor Details

This class inherits a constructor from SpotFlow::Bpmn::Step

Instance Method Details

#execute(execution) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/spot_flow/bpmn/gateway.rb', line 7

def execute(execution)
  if converging?
    if is_enabled?(execution)
      return leave(execution)
    else
      execution.wait
    end
  else
    return leave(execution)
  end
end

#is_enabled?(execution) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/spot_flow/bpmn/gateway.rb', line 22

def is_enabled?(execution)
  filled = []
  empty = []

  incoming.each { |flow| execution.tokens_in.include?(flow.id) ? filled.push(flow) : empty.push(flow) }

  # Filled slots don't need to be searched for tokens
  index = 0
  while (index < filled.length)
    current_flow = filled[index]
    current_flow.source.incoming.each do |incoming_flow|
      filled.push(incoming_flow) unless filled.include?(incoming_flow) || incoming_flow.target == self
    end
    index = index + 1
  end

  # Empty slots need to be searched for tokens
  index = 0
  while (index < empty.length)
    current_flow = empty[index]
    current_flow.source.incoming.each do |incoming_flow|
      empty.push(incoming_flow) unless filled.include?(incoming_flow) || empty.include?(incoming_flow) || incoming_flow.target == self
    end
    index = index + 1
  end

  empty_ids = empty.map { |g| g.id }

  # If there are empty slots with tokens we need to wait
  return false if (empty_ids & execution.parent.tokens).length > 0
  return true
end