simple-event-bus

Simple event bus. Easily emit and handle events.


Keywords
emit-events, event-bus, publish-subscribe, rails, ruby
License
MIT
Install
gem install simple-event-bus -v 0.1.1

Documentation

SimpleEventBus

Install

Gemfile:

gem 'simple-event-bus'

Shell:

gem install simple-event-bus

Usage

Use the SimpleEventBus class as a singleton, or instantiate new instances of it.

require 'event-bus'

SimpleEventBus.subscribe(:event_happened) do |params|
  puts "Event handled with block: #{params.inspect}"
end

class EventHandler
  def event_happened(params)
    puts "Event handled with method: #{params.inspect}"
  end
end

SimpleEventBus.emit(:event_happened, param1: 'hello', param2: 'world')

bus = SimpleEventBus.new

bus.subscribe(:event_happened, EventHandler.new, once: true)

bus.emit(:event_happened, request: 'handle THIS')