Class: SimpleFlow::Pipeline::ParallelBlock

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_flow/pipeline.rb

Overview

Helper class for building parallel blocks

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pipeline) ⇒ ParallelBlock

Returns a new instance of ParallelBlock.



475
476
477
478
# File 'lib/simple_flow/pipeline.rb', line 475

def initialize(pipeline)
  @pipeline = pipeline
  @steps = []
end

Instance Attribute Details

#stepsObject (readonly)

Returns the value of attribute steps.



473
474
475
# File 'lib/simple_flow/pipeline.rb', line 473

def steps
  @steps
end

Instance Method Details

#step(name_or_callable = nil, callable = nil, depends_on: [], &block) ⇒ Object



480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
# File 'lib/simple_flow/pipeline.rb', line 480

def step(name_or_callable = nil, callable = nil, depends_on: [], &block)
  if name_or_callable.is_a?(Symbol)
    name = name_or_callable
    callable ||= block
    raise ArgumentError, "Step must respond to #call" unless callable.respond_to?(:call)
    callable = @pipeline.send(:apply_middleware, callable)
    # Register the step in the pipeline's named_steps
    @pipeline.instance_variable_get(:@named_steps)[name] = callable
    @steps << { name: name, callable: callable, type: :named }
  else
    callable = name_or_callable || block
    raise ArgumentError, "Step must respond to #call" unless callable.respond_to?(:call)
    callable = @pipeline.send(:apply_middleware, callable)
    @steps << { callable: callable, type: :unnamed }
  end
  self
end