Class: Processable
- Inherits:
-
Object
- Object
- Processable
- Defined in:
- lib/processable.rb
Overview
Defined Under Namespace
Classes: Error
Constant Summary collapse
- @@registered_steps =
Collections of steps like
[]
Class Method Summary collapse
-
.step(name) {|block| ... } ⇒ Object
Adding new step to the process.
Instance Method Summary collapse
-
#process ⇒ Object
Run steps in order as they were defined.
Class Method Details
.step(name) {|block| ... } ⇒ Object
Adding new step to the process
28 29 30 |
# File 'lib/processable.rb', line 28 def step(name, &block) @@registered_steps = @@registered_steps << { name: name, block: block } end |
Instance Method Details
#process ⇒ Object
Run steps in order as they were defined
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/processable.rb', line 34 def process @@registered_steps.each_with_index do |step, index| previous_step = index.zero? ? {} : @@registered_steps[index - 1] result = instance_exec(previous_step[:result], step, @@registered_steps, &step[:block]) step[:result] = result end @@registered_steps.last[:result] end |