Sha256: 5ccfc44d856722845e786f77eaf555fd2706e908ef05207ab9369ecfe4af89c0

Contents?: true

Size: 588 Bytes

Versions: 6

Compression:

Stored size: 588 Bytes

Contents

# 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'

module Lux::EventBus
  extend self

  EVENTS = {}

  def on name, key=nil, &proc
    key ||= caller[0].split(':in ').first.gsub(/[^\w]/,'')

    EVENTS[name] ||= {}
    EVENTS[name][key] ||= proc
  end

  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
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
lux-fw-0.5.37 ./lib/lux/event_bus/event_bus.rb
lux-fw-0.5.36 ./lib/lux/event_bus/event_bus.rb
lux-fw-0.5.35 ./lib/lux/event_bus/event_bus.rb
lux-fw-0.5.34 ./lib/lux/event_bus/event_bus.rb
lux-fw-0.5.33 ./lib/lux/event_bus/event_bus.rb
lux-fw-0.5.32 ./lib/lux/event_bus/event_bus.rb