Class: Bricolage::EventHandlers

Inherits:
Object
  • Object
show all
Defined in:
lib/bricolage/eventhandlers.rb

Instance Method Summary collapse

Constructor Details

#initializeEventHandlers

Returns a new instance of EventHandlers.



3
4
5
# File 'lib/bricolage/eventhandlers.rb', line 3

def initialize
  @handlers = []
end

Instance Method Details

#add(handler) ⇒ Object



7
8
9
# File 'lib/bricolage/eventhandlers.rb', line 7

def add(handler)
  @handlers.push handler
end

#run(event) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/bricolage/eventhandlers.rb', line 11

def run(event)
  @handlers.each do |h|
    begin
      h.call(event)
    rescue => err
      $stderr.puts "hook error: #{err.class}: #{err.message}"
      err.backtrace.each do |line|
        $stderr.puts "\t#{line}"
      end
    end
  end
end