Class: Yaks::Pipeline
- Inherits:
-
Object
- Object
- Yaks::Pipeline
- Defined in:
- lib/yaks/pipeline.rb
Instance Method Summary collapse
Instance Method Details
#call(input, env) ⇒ Object
5 6 7 |
# File 'lib/yaks/pipeline.rb', line 5 def call(input, env) steps.inject(input) {|memo, (_, step)| step.call(memo, env) } end |
#insert_hooks(hooks) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/yaks/pipeline.rb', line 9 def insert_hooks(hooks) new_steps = hooks.inject(steps) do |steps, (type, target_step, name, hook)| steps.flat_map do |step_name, callable| if step_name.equal? target_step case type when :before [[name, hook], [step_name, callable]] when :after [[step_name, callable], [name, hook]] when :around [[name, ->(x, env) { hook.call(x, env, &callable) }]] when :skip [] end end || [[step_name, callable]] end end self.class.new(new_steps) end |
#inverse ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/yaks/pipeline.rb', line 34 def inverse unless transitive? raise "Unable to get inverse pipeline, not all pipeline steps are transitive." end self.class.new(steps.map {|name, step| [name, step.inverse]}.reverse) end |
#transitive? ⇒ Boolean
30 31 32 |
# File 'lib/yaks/pipeline.rb', line 30 def transitive? steps.all? {|_name, step| step.respond_to?(:transitive?) && step.transitive?} end |