class NxtPipeline::Callbacks
Attributes
pipeline[R]
registry[R]
Public Class Methods
new(pipeline:)
click to toggle source
# File lib/nxt_pipeline/callbacks.rb, line 3 def initialize(pipeline:) @registry = build_registry @pipeline = pipeline end
Public Instance Methods
around(type, change_set, &execution)
click to toggle source
# File lib/nxt_pipeline/callbacks.rb, line 18 def around(type, change_set, &execution) around_callbacks = registry.resolve!(:around, type) return execution.call unless around_callbacks.any? callback_chain = around_callbacks.reverse.inject(execution) do |previous, callback| -> { callback.call(pipeline, change_set, previous) } end callback_chain.call end
register(path, callback)
click to toggle source
# File lib/nxt_pipeline/callbacks.rb, line 8 def register(path, callback) registry.resolve!(*path) << callback end
run(kind_of_callback, type, change_set)
click to toggle source
# File lib/nxt_pipeline/callbacks.rb, line 12 def run(kind_of_callback, type, change_set) registry.resolve!(kind_of_callback, type).each do |callback| run_callback(callback, change_set) end end
Private Instance Methods
build_registry()
click to toggle source
# File lib/nxt_pipeline/callbacks.rb, line 39 def build_registry NxtRegistry::Registry.new(:callbacks) do register(:before) do register(:step, []) register(:execution, []) end register(:around) do register(:step, []) register(:execution, []) end register(:after) do register(:step, []) register(:execution, []) end end end
run_callback(callback, change_set)
click to toggle source
# File lib/nxt_pipeline/callbacks.rb, line 33 def run_callback(callback, change_set) args = [pipeline, change_set] args = args.take(callback.arity) callback.call(*args) end