Class: Gurke::Configuration::HookSet Private

Inherits:
Object
  • Object
show all
Defined in:
lib/gurke/configuration.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Defined Under Namespace

Classes: Context

Instance Method Summary collapse

Constructor Details

#initializeHookSet

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of HookSet.



132
133
134
135
136
# File 'lib/gurke/configuration.rb', line 132

def initialize
  @before = []
  @after  = []
  @around = []
end

Instance Method Details

#append(set, hook) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



138
139
140
141
142
143
144
145
# 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) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



147
148
149
150
151
152
153
154
155
156
157
158
159
# 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|
    hook.run world, ctx
  rescue StandardError => e
    warn "Rescued error in after hook: #{e}\n#{e.backtrace.join("\n")}"
  end
end