Class: ActiveSupport::Notifications::Fanout

Inherits:
Object
  • Object
show all
Defined in:
lib/active_support/notifications/fanout.rb

Overview

This is a default queue implementation that ships with Notifications. It just pushes events to all registered log subscribers.

Defined Under Namespace

Classes: Binding, Subscriber

Instance Method Summary collapse

Constructor Details

#initializeFanout

Returns a new instance of Fanout.



6
7
8
9
# File 'lib/active_support/notifications/fanout.rb', line 6

def initialize
  @subscribers = []
  @listeners_for = {}
end

Instance Method Details

#bind(pattern) ⇒ Object



11
12
13
# File 'lib/active_support/notifications/fanout.rb', line 11

def bind(pattern)
  Binding.new(self, pattern)
end

#publish(name, *args) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/active_support/notifications/fanout.rb', line 26

def publish(name, *args)
  if listeners = @listeners_for[name]
    listeners.each { |s| s.publish(name, *args) }
  else
    @listeners_for[name] = @subscribers.select { |s| s.publish(name, *args) }
  end
end

#subscribe(pattern = nil, &block) ⇒ Object



15
16
17
18
19
# File 'lib/active_support/notifications/fanout.rb', line 15

def subscribe(pattern = nil, &block)
  @listeners_for.clear
  @subscribers << Subscriber.new(pattern, &block)
  @subscribers.last
end

#unsubscribe(subscriber) ⇒ Object



21
22
23
24
# File 'lib/active_support/notifications/fanout.rb', line 21

def unsubscribe(subscriber)
  @listeners_for.clear
  @subscribers.reject! {|s| s.matches?(subscriber)}
end

#waitObject

This is a sync queue, so there is not waiting.



35
36
# File 'lib/active_support/notifications/fanout.rb', line 35

def wait
end