Class: Dynflow::Flows::AbstractComposed

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

Direct Known Subclasses

Concurrence, Sequence

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Abstract

#empty?, #includes_step?

Methods inherited from Serializable

constantize, from_hash

Constructor Details

#initialize(flows) ⇒ AbstractComposed

Returns a new instance of AbstractComposed.



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

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.



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

def flows
  @flows
end

Instance Method Details

#<<(v) ⇒ Object



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

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

#[](*args) ⇒ Object



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

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

#[]=(*args) ⇒ Object



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

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

#add_and_resolve(dependency_graph, new_flow) ⇒ Object



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

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



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

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

#flatten!Object



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

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



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

def size
  @flows.size
end

#to_hashObject



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

def to_hash
  super.merge recursive_to_hash(:flows => flows)
end