Class: Wisper::GlobalListeners

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/wisper/global_listeners.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGlobalListeners

Returns a new instance of GlobalListeners.



9
10
11
12
# File 'lib/wisper/global_listeners.rb', line 9

def initialize
  @registrations = Set.new
  @mutex         = Mutex.new
end

Class Method Details

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



31
32
33
# File 'lib/wisper/global_listeners.rb', line 31

def self.add_listener(listener, options = {})
  instance.add_listener(listener, options)
end

.clearObject



43
44
45
# File 'lib/wisper/global_listeners.rb', line 43

def self.clear
  instance.clear
end

.listenersObject



39
40
41
# File 'lib/wisper/global_listeners.rb', line 39

def self.listeners
  instance.listeners
end

.registrationsObject



35
36
37
# File 'lib/wisper/global_listeners.rb', line 35

def self.registrations
  instance.registrations
end

Instance Method Details

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



14
15
16
17
# File 'lib/wisper/global_listeners.rb', line 14

def add_listener(listener, options = {})
  with_mutex { @registrations << ObjectRegistration.new(listener, options) }
  self
end

#clearObject



27
28
29
# File 'lib/wisper/global_listeners.rb', line 27

def clear
  with_mutex { @registrations.clear }
end

#listenersObject



23
24
25
# File 'lib/wisper/global_listeners.rb', line 23

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

#registrationsObject



19
20
21
# File 'lib/wisper/global_listeners.rb', line 19

def registrations
  with_mutex { @registrations }
end