Class: Wisper::TemporaryListeners Private

Inherits:
Object
  • Object
show all
Defined in:
lib/wisper/temporary_listeners.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.registrationsObject

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.



12
13
14
# File 'lib/wisper/temporary_listeners.rb', line 12

def self.registrations
  new.registrations
end

.subscribe(*listeners, &block) ⇒ 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.



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

def self.subscribe(*listeners, &block)
  new.subscribe(*listeners, &block)
end

Instance Method Details

#registrationsObject

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.



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

def registrations
  Thread.current[key] ||= Set.new
end

#subscribe(*listeners, &block) ⇒ 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.



16
17
18
19
20
21
22
23
24
25
# File 'lib/wisper/temporary_listeners.rb', line 16

def subscribe(*listeners, &block)
  options = listeners.last.is_a?(Hash) ? listeners.pop : {}
  begin
    listeners.each { |listener| registrations << ObjectRegistration.new(listener, options) }
    yield
  ensure
    clear
  end
  self
end