Class: ActiveSupport::Notifications::Fanout
- Inherits:
-
Object
- Object
- ActiveSupport::Notifications::Fanout
- 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: Subscriber
Instance Method Summary collapse
-
#initialize ⇒ Fanout
constructor
A new instance of Fanout.
- #listeners_for(name) ⇒ Object
- #listening?(name) ⇒ Boolean
- #publish(name, *args) ⇒ Object
- #subscribe(pattern = nil, block = Proc.new) ⇒ Object
- #unsubscribe(subscriber) ⇒ Object
-
#wait ⇒ Object
This is a sync queue, so there is no waiting.
Constructor Details
#initialize ⇒ Fanout
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
#listeners_for(name) ⇒ Object
27 28 29 |
# File 'lib/active_support/notifications/fanout.rb', line 27 def listeners_for(name) @listeners_for[name] ||= @subscribers.select { |s| s.subscribed_to?(name) } end |
#listening?(name) ⇒ Boolean
31 32 33 |
# File 'lib/active_support/notifications/fanout.rb', line 31 def listening?(name) listeners_for(name).any? end |
#publish(name, *args) ⇒ Object
23 24 25 |
# File 'lib/active_support/notifications/fanout.rb', line 23 def publish(name, *args) listeners_for(name).each { |s| s.publish(name, *args) } end |
#subscribe(pattern = nil, block = Proc.new) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/active_support/notifications/fanout.rb', line 11 def subscribe(pattern = nil, block = Proc.new) subscriber = Subscriber.new(pattern, block) @subscribers << subscriber @listeners_for.clear subscriber end |
#unsubscribe(subscriber) ⇒ Object
18 19 20 21 |
# File 'lib/active_support/notifications/fanout.rb', line 18 def unsubscribe(subscriber) @subscribers.reject! { |s| s.matches?(subscriber) } @listeners_for.clear end |
#wait ⇒ Object
This is a sync queue, so there is no waiting.
36 37 |
# File 'lib/active_support/notifications/fanout.rb', line 36 def wait end |