class Wisper::TemporaryListeners
Public Class Methods
registrations()
click to toggle source
# File lib/wisper/temporary_listeners.rb, line 11 def self.registrations new.registrations end
subscribe(*listeners, &block)
click to toggle source
# File lib/wisper/temporary_listeners.rb, line 7 def self.subscribe(*listeners, &block) new.subscribe(*listeners, &block) end
Public Instance Methods
registrations()
click to toggle source
# File lib/wisper/temporary_listeners.rb, line 27 def registrations Thread.current[key] ||= Set.new end
subscribe(*listeners) { || ... }
click to toggle source
# File lib/wisper/temporary_listeners.rb, line 15 def subscribe(*listeners, &_block) new_registrations = build_registrations(listeners) begin registrations.merge new_registrations yield ensure registrations.subtract new_registrations end self end
Private Instance Methods
build_registrations(listeners)
click to toggle source
# File lib/wisper/temporary_listeners.rb, line 33 def build_registrations(listeners) options = listeners.last.is_a?(Hash) ? listeners.pop : {} listeners.map { |listener| ObjectRegistration.new(listener, options) } end
key()
click to toggle source
# File lib/wisper/temporary_listeners.rb, line 38 def key '__wisper_temporary_listeners' end