Class: Gilmour::Composers::Compose

Inherits:
Pipeline
  • Object
show all
Defined in:
lib/gilmour/composers.rb

Instance Attribute Summary

Attributes inherited from Pipeline

#pipeline

Instance Method Summary collapse

Methods inherited from Pipeline

#continuation, #initialize

Constructor Details

This class inherits a constructor from Gilmour::Composers::Pipeline

Instance Method Details

#execute(msg = {}, &blk) ⇒ Object

Execute a pipeline. The output of the last stage of the pipeline is passed to the block, if all stages are successful. Otherwise, the output of the last successful stage is passed, along with the conitnuation which represents the remaining pipeline



81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/gilmour/composers.rb', line 81

def execute(msg = {}, &blk)
  blk.call(nil, nil) if pipeline.empty?
  handler = proc do |queue, data, code|
    if queue.empty? || code != 200
      blk.call(data, code, continuation(queue))
    else
      head = queue.first
      tail = queue[1..-1]
      head.execute(data, &handler.curry[tail])
    end
  end
  handler.call(pipeline, msg, 200)
end