Class: Gurke::Configuration::HookSet Private
- Inherits:
-
Object
- Object
- Gurke::Configuration::HookSet
- 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
- #append(set, hook) ⇒ Object private
-
#initialize ⇒ HookSet
constructor
private
A new instance of HookSet.
- #run(context, world, &block) ⇒ Object private
Constructor Details
#initialize ⇒ HookSet
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.
112 113 114 115 116 |
# File 'lib/gurke/configuration.rb', line 112 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.
118 119 120 121 122 123 124 125 |
# File 'lib/gurke/configuration.rb', line 118 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.
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/gurke/configuration.rb', line 127 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 => e warn "Rescued error in after hook: #{e}\n#{e.backtrace.join("\n")}" end end end |