Class: Dynflow::Flows::AbstractComposed

Inherits:
Abstract show all
Defined in:
lib/dynflow/flows/abstract_composed.rb

Direct Known Subclasses

Concurrence, Sequence

Constant Summary

Constants inherited from Serializable

Serializable::LEGACY_TIME_FORMAT, Serializable::TIME_FORMAT

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Abstract

decode, #empty?, #includes_step?, new_from_hash, #to_hash

Methods inherited from Serializable

constantize, from_hash, new_from_hash, #to_hash

Constructor Details

#initialize(flows) ⇒ AbstractComposed

Returns a new instance of AbstractComposed.



8
9
10
11
12
# File 'lib/dynflow/flows/abstract_composed.rb', line 8

def initialize(flows)
  Type! flows, Array
  flows.all? { |f| Type! f, Abstract }
  @flows = flows
end

Instance Attribute Details

#flowsObject (readonly) Also known as: sub_flows

Returns the value of attribute flows.



6
7
8
# File 'lib/dynflow/flows/abstract_composed.rb', line 6

def flows
  @flows
end

Instance Method Details

#<<(v) ⇒ Object



18
19
20
21
# File 'lib/dynflow/flows/abstract_composed.rb', line 18

def <<(v)
  @flows << v
  self
end

#[](*args) ⇒ Object



23
24
25
# File 'lib/dynflow/flows/abstract_composed.rb', line 23

def [](*args)
  @flows[*args]
end

#[]=(*args) ⇒ Object



27
28
29
# File 'lib/dynflow/flows/abstract_composed.rb', line 27

def []=(*args)
  @flows.[]=(*args)
end

#add_and_resolve(dependency_graph, new_flow) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/dynflow/flows/abstract_composed.rb', line 42

def add_and_resolve(dependency_graph, new_flow)
  return if new_flow.empty?

  satisfying_flows = find_satisfying_sub_flows(dependency_graph, new_flow)
  add_to_sequence(satisfying_flows, new_flow)
  flatten!
end

#all_step_idsArray<Integer>

Returns all step_ids recursively in the flow.

Returns:

  • (Array<Integer>)

    all step_ids recursively in the flow



38
39
40
# File 'lib/dynflow/flows/abstract_composed.rb', line 38

def all_step_ids
  flows.map(&:all_step_ids).flatten
end

#encodeObject



14
15
16
# File 'lib/dynflow/flows/abstract_composed.rb', line 14

def encode
  [Registry.encode(self)] + flows.map(&:encode)
end

#flatten!Object



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/dynflow/flows/abstract_composed.rb', line 50

def flatten!
  self.sub_flows.to_enum.with_index.reverse_each do |flow, i|
    if flow.class == self.class
      expand_steps(i)
    elsif flow.is_a?(AbstractComposed) && flow.sub_flows.size == 1
      self.sub_flows[i] = flow.sub_flows.first
    end
  end

  self.sub_flows.map(&:flatten!)
end

#sizeObject



31
32
33
# File 'lib/dynflow/flows/abstract_composed.rb', line 31

def size
  @flows.size
end