Class: Gilmour::Composers::Batch

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

Constructor Details

#initialize(backend, spec) ⇒ Batch

:nodoc:



154
155
156
157
# File 'lib/gilmour/composers.rb', line 154

def initialize(backend, spec) #:nodoc:
  super(backend, spec)
  @record = false
end

Instance Method Details

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

Execute the batch pipeline. This pipeline ignores all errors step is passed to block. See the documentation of the #batch method for more details



166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/gilmour/composers.rb', line 166

def execute(data={}, &blk)
  results = []
  blk.call(nil, nil) if pipeline.empty?
  handler = proc do |queue, data, code|
    results << {data: data, code: code} if @record
    if queue.empty?
      result = @record ? results[1..-1] : data
      blk.call(result, code)
    else
      head = queue.first
      tail = queue[1..-1]
      head.execute(&handler.curry[tail])
    end
  end
  handler.call(pipeline, nil, 200)
end

#with_recorder(record = true) ⇒ Object



159
160
161
162
# File 'lib/gilmour/composers.rb', line 159

def with_recorder(record=true)
  @record = record
  self
end