class Dynflow::Flows::AbstractComposed
Attributes
flows[R]
sub_flows[R]
Public Class Methods
new(flows)
click to toggle source
# File lib/dynflow/flows/abstract_composed.rb, line 8 def initialize(flows) Type! flows, Array flows.all? { |f| Type! f, Abstract } @flows = flows end
Public Instance Methods
<<(v)
click to toggle source
# File lib/dynflow/flows/abstract_composed.rb, line 18 def <<(v) @flows << v self end
[](*args)
click to toggle source
# File lib/dynflow/flows/abstract_composed.rb, line 23 def [](*args) @flows[*args] end
[]=(*args)
click to toggle source
# File lib/dynflow/flows/abstract_composed.rb, line 27 def []=(*args) @flows.[]=(*args) end
add_and_resolve(dependency_graph, new_flow)
click to toggle source
# 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_ids()
click to toggle source
@return [Array<Integer>] all step_ids recursively in the flow
# File lib/dynflow/flows/abstract_composed.rb, line 38 def all_step_ids flows.map(&:all_step_ids).flatten end
encode()
click to toggle source
# File lib/dynflow/flows/abstract_composed.rb, line 14 def encode [Registry.encode(self)] + flows.map(&:encode) end
flatten!()
click to toggle source
# 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
size()
click to toggle source
# File lib/dynflow/flows/abstract_composed.rb, line 31 def size @flows.size end
Protected Instance Methods
add_to_sequence(satisfying_flows, new_flow)
click to toggle source
adds the new_flow
in a way that it's in sequence with the satisfying_flows
# File lib/dynflow/flows/abstract_composed.rb, line 66 def add_to_sequence(satisfying_flows, new_flow) raise NotImplementedError end
Private Instance Methods
expand_steps(index)
click to toggle source
# File lib/dynflow/flows/abstract_composed.rb, line 89 def expand_steps(index) expanded_step = self.sub_flows[index] self.sub_flows.delete_at(index) expanded_step.sub_flows.each do |flow| self.sub_flows.insert(index, flow) index += 1 end end
find_satisfying_sub_flows(dependency_graph, new_flow)
click to toggle source
# File lib/dynflow/flows/abstract_composed.rb, line 72 def find_satisfying_sub_flows(dependency_graph, new_flow) satisfying_flows = Set.new new_flow.all_step_ids.each do |step_id| dependency_graph.required_step_ids(step_id).each do |required_step_id| satisfying_flow = sub_flows.find do |flow| flow.includes_step?(required_step_id) end if satisfying_flow satisfying_flows << satisfying_flow dependency_graph.mark_satisfied(step_id, required_step_id) end end end return satisfying_flows.to_a end