Class: Yarrow::Process::Workflow
- Inherits:
-
Object
- Object
- Yarrow::Process::Workflow
- Defined in:
- lib/yarrow/process/workflow.rb
Instance Method Summary collapse
- #connect(processor) ⇒ Object
-
#initialize(input) ⇒ Workflow
constructor
A new instance of Workflow.
- #process(&block) ⇒ Object
Constructor Details
#initialize(input) ⇒ Workflow
Returns a new instance of Workflow.
4 5 6 7 |
# File 'lib/yarrow/process/workflow.rb', line 4 def initialize(input) @input = input @processors = [] end |
Instance Method Details
#connect(processor) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/yarrow/process/workflow.rb', line 9 def connect(processor) provided_input = if @processors.any? @processors.last.provides else @input.class.to_s end if processor.can_accept?(provided_input) @processors << processor else raise ArgumentError.new( "`#{processor.class}` accepts `#{processor.accepts}` but was connected to `#{provided_input}`" ) end end |
#process(&block) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/yarrow/process/workflow.rb', line 25 def process(&block) result = @input @processors.each do |processor| result = processor.process(result) end block.call(result) end |