lib/nxt_pipeline/callbacks.rb in nxt_pipeline-1.0.0 vs lib/nxt_pipeline/callbacks.rb in nxt_pipeline-2.0.0

- old
+ new

@@ -8,32 +8,35 @@ def register(path, callback) registry.resolve!(*path) << callback end def run(kind_of_callback, type, change_set) - registry.resolve!(kind_of_callback, type).each do |callback| - run_callback(callback, change_set) + callbacks = registry.resolve!(kind_of_callback, type) + return unless callbacks.any? + + callbacks.inject(change_set) do |changes, callback| + run_callback(callback, changes) end end 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) } + -> { callback.call(change_set, previous, pipeline) } end callback_chain.call end private attr_reader :registry, :pipeline def run_callback(callback, change_set) - args = [pipeline, change_set] - args = args.take(callback.arity) + args = [change_set, pipeline] + args = args.take(callback.arity) unless callback.arity.negative? callback.call(*args) end def build_registry NxtRegistry::Registry.new(:callbacks) do