Class: ActiveSupport::Notifications::Fanout

Inherits:
Object
  • Object
show all
Defined in:
activesupport/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.

Instance Method Summary (collapse)

Constructor Details

- (Fanout) initialize

A new instance of Fanout



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

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

Instance Method Details

- (Object) listeners_for(name)



28
29
30
# File 'activesupport/lib/active_support/notifications/fanout.rb', line 28

def listeners_for(name)
  @listeners_for[name] ||= @subscribers.select { |s| s.subscribed_to?(name) }
end

- (Boolean) listening?(name)

Returns:

  • (Boolean)


32
33
34
# File 'activesupport/lib/active_support/notifications/fanout.rb', line 32

def listening?(name)
  listeners_for(name).any?
end

- (Object) publish(name, *args)



24
25
26
# File 'activesupport/lib/active_support/notifications/fanout.rb', line 24

def publish(name, *args)
  listeners_for(name).each { |s| s.publish(name, *args) }
end

- (Object) subscribe(pattern = nil, block = Proc.new)



11
12
13
14
15
16
17
# File 'activesupport/lib/active_support/notifications/fanout.rb', line 11

def subscribe(pattern = nil, block = Proc.new)
  subscriber = Subscriber.new(pattern, block).tap do |s|
    @subscribers << s
  end
  @listeners_for.clear
  subscriber
end

- (Object) unsubscribe(subscriber)



19
20
21
22
# File 'activesupport/lib/active_support/notifications/fanout.rb', line 19

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

- (Object) wait

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



37
38
# File 'activesupport/lib/active_support/notifications/fanout.rb', line 37

def wait
end