Class: Dry::Events::Listener
- Inherits:
-
Module
- Object
- Module
- Dry::Events::Listener
- Defined in:
- lib/dry/events/listener.rb
Overview
Extension for objects that can listen to events
Instance Attribute Summary collapse
-
#:id(: id) ⇒ Symbol, String
readonly
private
The publisher identifier.
- #id ⇒ Object readonly
Class Method Summary collapse
-
.[](id) ⇒ Module
Create a listener extension for a specific publisher.
Instance Method Summary collapse
- #included(klass) ⇒ Object private
-
#initialize(id) ⇒ Listener
constructor
private
A new instance of Listener.
Constructor Details
#initialize(id) ⇒ Listener
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 Listener.
43 44 45 46 47 48 49 50 |
# File 'lib/dry/events/listener.rb', line 43 def initialize(id) super() @id = id define_method(:subscribe) do |event_id, query = EMPTY_HASH, &block| Publisher.registry[id].subscribe(event_id, query, &block) end end |
Instance Attribute Details
#:id(: id) ⇒ Symbol, String (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.
Returns The publisher identifier.
31 |
# File 'lib/dry/events/listener.rb', line 31 attr_reader :id |
#id ⇒ Object (readonly)
31 32 33 |
# File 'lib/dry/events/listener.rb', line 31 def id @id end |
Class Method Details
.[](id) ⇒ Module
Create a listener extension for a specific publisher
38 39 40 |
# File 'lib/dry/events/listener.rb', line 38 def self.[](id) new(id) end |
Instance Method Details
#included(klass) ⇒ 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.
53 54 55 56 |
# File 'lib/dry/events/listener.rb', line 53 def included(klass) klass.extend(self) super end |