Module: RSMP::Notifier

Includes:
Inspect
Included in:
Proxy
Defined in:
lib/rsmp/notifier.rb

Instance Method Summary collapse

Methods included from Inspect

#inspector

Instance Method Details

#add_listener(listener) ⇒ Object

Raises:

  • (ArgumentError)

15
16
17
18
# File 'lib/rsmp/notifier.rb', line 15

def add_listener listener
  raise ArgumentError unless listener
  @listeners << listener unless @listeners.include? listener
end

#initialize_distributorObject


11
12
13
# File 'lib/rsmp/notifier.rb', line 11

def initialize_distributor
  @listeners = []
end

#inspectObject


7
8
9
# File 'lib/rsmp/notifier.rb', line 7

def inspect
  "#<#{self.class.name}:#{self.object_id}, #{inspector(:@listeners)}>"
end

#notify(message) ⇒ Object


25
26
27
# File 'lib/rsmp/notifier.rb', line 25

def notify message
  @listeners.each { |listener| listener.notify message }
end

#remove_listener(listener) ⇒ Object

Raises:

  • (ArgumentError)

20
21
22
23
# File 'lib/rsmp/notifier.rb', line 20

def remove_listener listener
  raise ArgumentError unless listener
  @listeners.delete listener
end