Module: Wisper::Publisher
- Defined in:
- lib/wisper/publisher.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #listeners ⇒ Object
-
#on(*events, &block) ⇒ self
subscribe a block.
-
#subscribe(listener, **options) ⇒ self
subscribe a listener.
Instance Method Details
#listeners ⇒ Object
3 4 5 |
# File 'lib/wisper/publisher.rb', line 3 def listeners registrations.map(&:listener).freeze end |
#on(*events, &block) ⇒ self
subscribe a block
25 26 27 28 29 30 |
# File 'lib/wisper/publisher.rb', line 25 def on(*events, &block) raise ArgumentError, 'must give at least one event' if events.empty? raise ArgumentError, 'must pass a block' if !block local_registrations << BlockRegistration.new(block, on: events) self end |
#subscribe(listener, **options) ⇒ self
subscribe a listener
13 14 15 16 17 |
# File 'lib/wisper/publisher.rb', line 13 def subscribe(listener, **) raise ArgumentError, "#{__method__} does not take a block, did you mean to call #on instead?" if block_given? local_registrations << ObjectRegistration.new(listener, **) self end |