Class: Whoosh::Instrumentation
- Inherits:
-
Object
- Object
- Whoosh::Instrumentation
- Defined in:
- lib/whoosh/instrumentation.rb
Instance Method Summary collapse
- #emit(event, data = {}) ⇒ Object
-
#initialize ⇒ Instrumentation
constructor
A new instance of Instrumentation.
- #on(event, &block) ⇒ Object
Constructor Details
#initialize ⇒ Instrumentation
Returns a new instance of Instrumentation.
6 7 8 |
# File 'lib/whoosh/instrumentation.rb', line 6 def initialize @subscribers = Hash.new { |h, k| h[k] = [] } end |
Instance Method Details
#emit(event, data = {}) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/whoosh/instrumentation.rb', line 14 def emit(event, data = {}) @subscribers[event].each do |subscriber| subscriber.call(data) rescue => e # Don't let subscriber errors crash the app end end |
#on(event, &block) ⇒ Object
10 11 12 |
# File 'lib/whoosh/instrumentation.rb', line 10 def on(event, &block) @subscribers[event] << block end |