Module: Lux::EventBus
Overview
EventBus.on(‘test’) { |arg| puts ‘jedan: %s’ % arg } EventBus.on(‘test’) { |arg| puts ‘dva: %s’ % arg } EventBus.on(‘test’) { |arg| raise ‘abc’ } EventBus.call ‘test’, ‘xxx’
Constant Summary collapse
- EVENTS =
{}
Instance Method Summary collapse
Instance Method Details
#call(name, opts = nil) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/lux/event_bus/event_bus.rb', line 18 def call name, opts=nil for func in EVENTS[name].values begin func.call opts rescue => error Lux.config.on_event_bus_error.call error, name end end end |
#on(name, key = nil, &proc) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/lux/event_bus/event_bus.rb', line 11 def on name, key=nil, &proc key ||= caller[0].split(':in ').first.gsub(/[^\w]/,'') EVENTS[name] ||= {} EVENTS[name][key] ||= proc end |