Class: Rpruby::EventBus Private
- Inherits:
-
Object
- Object
- Rpruby::EventBus
- Defined in:
- lib/rpruby/event_bus.rb
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Instance Attribute Summary collapse
- #event_types ⇒ Object readonly private
Instance Method Summary collapse
- #broadcast(event_name, **attributes) ⇒ Object private
-
#initialize ⇒ EventBus
constructor
private
A new instance of EventBus.
- #on(event_name, &proc) ⇒ Object private
Constructor Details
#initialize ⇒ EventBus
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of EventBus.
8 9 10 11 12 13 |
# File 'lib/rpruby/event_bus.rb', line 8 def initialize @event_types = { prepare_start_item_request: Events::PrepareStartItemRequest } @handlers = {} end |
Instance Attribute Details
#event_types ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
6 7 8 |
# File 'lib/rpruby/event_bus.rb', line 6 def event_types @event_types end |
Instance Method Details
#broadcast(event_name, **attributes) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
19 20 21 22 |
# File 'lib/rpruby/event_bus.rb', line 19 def broadcast(event_name, **attributes) event = event_types.fetch(event_name).new(**attributes) handlers_for(event_name).each { |handler| handler.call(event) } end |
#on(event_name, &proc) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
15 16 17 |
# File 'lib/rpruby/event_bus.rb', line 15 def on(event_name, &proc) handlers_for(event_name) << proc end |