Class: Brainguy::SingleEventSubscription
- Inherits:
-
Subscription
- Object
- Subscription
- Brainguy::SingleEventSubscription
- Defined in:
- lib/brainguy/single_event_subscription.rb
Overview
A subscription to a single type (name) of event. The listener
will only
be notified if the event name matches subscribed_event_name
.
See Emitter#on for where this class is used.
Instance Attribute Summary
Attributes inherited from Subscription
Instance Method Summary collapse
-
#handle(event) ⇒ Object
Call listener if the event name is the one being subscribed to.
-
#initialize(owner, listener, subscribed_event_name) ⇒ SingleEventSubscription
constructor
A new instance of SingleEventSubscription.
Methods inherited from Subscription
Constructor Details
#initialize(owner, listener, subscribed_event_name) ⇒ SingleEventSubscription
Returns a new instance of SingleEventSubscription.
13 14 15 16 |
# File 'lib/brainguy/single_event_subscription.rb', line 13 def initialize(owner, listener, subscribed_event_name) @subscribed_event_name = subscribed_event_name super(owner, listener) end |
Instance Method Details
#handle(event) ⇒ Object
Call listener if the event name is the one being subscribed to.
20 21 22 23 |
# File 'lib/brainguy/single_event_subscription.rb', line 20 def handle(event) return unless event.name == @subscribed_event_name @listener.call(*event.args) end |