class Gurke::Configuration::HookSet

@api private

Public Class Methods

new() click to toggle source
# File lib/gurke/configuration.rb, line 132
def initialize
  @before = []
  @after  = []
  @around = []
end

Public Instance Methods

append(set, hook) click to toggle source
# File lib/gurke/configuration.rb, line 138
def append(set, hook)
  case set
    when :before then @before << hook
    when :after  then @after << hook
    when :around then @around << hook
    else raise ArgumentError.new "Unknown hook set: #{set}"
  end
end
run(context, world, &block) click to toggle source
# File lib/gurke/configuration.rb, line 147
def run(context, world, &block)
  ctx = Context.new context, block
  @before.each {|hook| hook.run world, ctx }
  @around.reduce Context.new(context, block) do |c, e|
    Context.new(context, -> { e.run world, c })
  end.call
ensure
  @after.each do |hook|
    begin
      hook.run world, ctx
    rescue StandardError => e
      warn "Rescued error in after hook: #{e}\n#{e.backtrace.join("\n")}"
    end
  end
end