Class: MedPipe::Pipeline

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

Overview

直列に繋いだtaskを順番に実行するクラス

Instance Method Summary collapse

Constructor Details

#initializePipeline

Returns a new instance of Pipeline.



5
6
7
# File 'lib/med_pipe/pipeline.rb', line 5

def initialize
  @tasks = []
end

Instance Method Details

#apply(task) ⇒ Object

Parameters:

  • task (Object)

    def call(context, prev_result, &block) を実装したクラス



10
11
12
13
# File 'lib/med_pipe/pipeline.rb', line 10

def apply(task)
  @tasks << task
  self
end

#run(context = {}) ⇒ Object

Parameters:

  • context (Hash) (defaults to: {})

    Stores data during pipeline execution



16
17
18
19
20
21
22
23
24
# File 'lib/med_pipe/pipeline.rb', line 16

def run(context = {}) = run_task_recursive(context)
# 展開すると以下のようになる
# @tasks[0].call(context, nil) do |prev_result|
#   @tasks[1].call(context, prev_result) do |prev_result|
#     @tasks[2].call(context, prev_result) do |prev_result|
#       nil
#     end
#   end
# end