Class: Conductor::Workflow::Dsl::ParallelBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/conductor/workflow/dsl/parallel_builder.rb

Overview

ParallelBuilder collects tasks defined in a parallel block. It proxies all method calls to the parent WorkflowBuilder and organizes the resulting tasks into parallel branches.

Examples:

parallel do
  simple :task1
  simple :task2
end

Instance Method Summary collapse

Constructor Details

#initialize(parent_builder) ⇒ ParallelBuilder

Returns a new instance of ParallelBuilder.



17
18
19
20
21
# File 'lib/conductor/workflow/dsl/parallel_builder.rb', line 17

def initialize(parent_builder)
  @parent = parent_builder
  @branches = []
  @current_branch = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, **kwargs, &block) ⇒ Object

Delegate all method calls to the parent builder and collect resulting TaskRefs



33
34
35
36
37
38
39
40
41
# File 'lib/conductor/workflow/dsl/parallel_builder.rb', line 33

def method_missing(name, *args, **kwargs, &block)
  if @parent.respond_to?(name, true)
    task_ref = @parent.send(name, *args, **kwargs, &block)
    @current_branch << task_ref if task_ref.is_a?(TaskRef)
    task_ref
  else
    super
  end
end

Instance Method Details

#finalizeArray<Array<TaskRef>>

Finalize the parallel block and return branches

Returns:

  • (Array<Array<TaskRef>>)

    Array of task branches



25
26
27
28
29
# File 'lib/conductor/workflow/dsl/parallel_builder.rb', line 25

def finalize
  # Add current branch if it has tasks
  @branches << @current_branch unless @current_branch.empty?
  @branches
end

#respond_to_missing?(name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/conductor/workflow/dsl/parallel_builder.rb', line 43

def respond_to_missing?(name, include_private = false)
  @parent.respond_to?(name, include_private) || super
end