class Rabbitek::Utils::HookWalker

Utility to work down the hooks setup

Attributes

hooks[R]

Public Class Methods

new(hooks = []) click to toggle source
# File lib/rabbitek/utils/hook_walker.rb, line 10
def initialize(hooks = [])
  @hooks = hooks.clone
end

Public Instance Methods

call!(*args) { |*args| ... } click to toggle source
# File lib/rabbitek/utils/hook_walker.rb, line 14
def call!(*args)
  return yield(*args) unless hooks.any?
  hook = hooks.pop

  debug "Calling hook: #{hook.class}"

  begin
    return_args = hook.call(*args) do |*new_args|
      hooks.any? ? call!(*new_args) { |*next_args| yield(*next_args) } : yield(*new_args)
    end
  ensure
    debug "Finishing hook: #{hook.class}"
  end

  return_args
end