Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mikhailvs/simple-event-bus
Simple event bus for Ruby
https://github.com/mikhailvs/simple-event-bus
emit-events event-bus publish-subscribe rails ruby
Last synced: 2 months ago
JSON representation
Simple event bus for Ruby
- Host: GitHub
- URL: https://github.com/mikhailvs/simple-event-bus
- Owner: mikhailvs
- License: mit
- Created: 2018-10-25T19:53:05.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-08-01T23:50:32.000Z (7 months ago)
- Last Synced: 2024-11-16T02:53:31.532Z (3 months ago)
- Topics: emit-events, event-bus, publish-subscribe, rails, ruby
- Language: Ruby
- Size: 14.6 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SimpleEventBus
[![Gem Version](https://badge.fury.io/rb/simple-event-bus.svg)](https://badge.fury.io/rb/simple-event-bus)## Install
Gemfile:
```ruby
gem 'simple-event-bus'
```Shell:
```sh
gem install simple-event-bus
```## Usage
Use the `SimpleEventBus` class as a singleton, or instantiate new instances of it.```ruby
require 'event-bus'SimpleEventBus.subscribe(:event_happened) do |params|
puts "Event handled with block: #{params.inspect}"
endclass EventHandler
def event_happened(params)
puts "Event handled with method: #{params.inspect}"
end
endSimpleEventBus.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')
```