Module: Wisper::Publisher

Included in:
TestWisperPublisher
Defined in:
lib/wisper/publisher.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#add_block_listener(options = {}, &block) ⇒ Object



18
19
20
21
22
# File 'lib/wisper/publisher.rb', line 18

def add_block_listener(options = {}, &block)
  warn "[DEPRECATED] use `on` instead of `add_block_listener`"
  local_registrations << BlockRegistration.new(block, options)
  self
end

#add_listener(listener, options = {}) ⇒ Object



24
25
26
27
# File 'lib/wisper/publisher.rb', line 24

def add_listener(listener, options = {})
  warn "[DEPRECATED] use `subscribe` instead of `add_listener`"
  subscribe(listener, options)
end

#listenersObject



3
4
5
# File 'lib/wisper/publisher.rb', line 3

def listeners
  registrations.map(&:listener).freeze
end

#on(*events, &block) ⇒ Object

Raises:

  • (ArgumentError)


12
13
14
15
16
# File 'lib/wisper/publisher.rb', line 12

def on(*events, &block)
  raise ArgumentError, 'must give at least one event' if events.empty?
  local_registrations << BlockRegistration.new(block, on: events)
  self
end

#respond_to(*events, &block) ⇒ Object



29
30
31
32
# File 'lib/wisper/publisher.rb', line 29

def respond_to(*events, &block)
  warn '[DEPRECATED] use `on` instead of `respond_to`'
  on(*events, &block)
end

#subscribe(listener, options = {}) ⇒ Object



7
8
9
10
# File 'lib/wisper/publisher.rb', line 7

def subscribe(listener, options = {})
  local_registrations << ObjectRegistration.new(listener, options)
  self
end