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 7 def initialize(flows) Type! flows, Array flows.all? { |f| Type! f, Abstract } @flows = flows end
Protected Class Methods
new_from_hash(hash)
click to toggle source
# File lib/dynflow/flows/abstract_composed.rb, line 63 def self.new_from_hash(hash) check_class_matching hash new(hash[:flows].map { |flow_hash| from_hash(flow_hash) }) end
Public Instance Methods
<<(v)
click to toggle source
# File lib/dynflow/flows/abstract_composed.rb, line 17 def <<(v) @flows << v self end
[](*args)
click to toggle source
# File lib/dynflow/flows/abstract_composed.rb, line 22 def [](*args) @flows[*args] end
[]=(*args)
click to toggle source
# File lib/dynflow/flows/abstract_composed.rb, line 26 def []=(*args) @flows.[]=(*args) end
add_and_resolve(dependency_graph, new_flow)
click to toggle source
# 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_ids()
click to toggle source
@return [Array<Integer>] all step_ids recursively in the flow
# File lib/dynflow/flows/abstract_composed.rb, line 37 def all_step_ids flows.map(&:all_step_ids).flatten end
flatten!()
click to toggle source
# 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
size()
click to toggle source
# File lib/dynflow/flows/abstract_composed.rb, line 30 def size @flows.size end
to_hash()
click to toggle source
Calls superclass method
Dynflow::Flows::Abstract#to_hash
# File lib/dynflow/flows/abstract_composed.rb, line 13 def to_hash super.merge recursive_to_hash(:flows => flows) 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 70 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 93 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 76 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