Class: 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: Binding, Subscriber
Instance Method Summary collapse
- #bind(pattern) ⇒ Object
-
#initialize ⇒ Fanout
constructor
A new instance of Fanout.
- #publish(name, *args) ⇒ Object
- #subscribe(pattern = nil, &block) ⇒ Object
- #unsubscribe(subscriber) ⇒ Object
-
#wait ⇒ Object
This is a sync queue, so there is not 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
#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 |
#wait ⇒ Object
This is a sync queue, so there is not waiting.
35 36 |
# File 'lib/active_support/notifications/fanout.rb', line 35 def wait end |