diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2012-03-21 11:12:46 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2012-03-21 11:12:58 -0700 |
commit | d99c790f65204520690c20f5789148f3c7e2bce8 (patch) | |
tree | d03fce08c38652bbda4dae5249c511eba1f45c53 /activesupport/lib/active_support/notifications | |
parent | 14b2cf6a0ae2bfd60efb7c3146145bf005853cc3 (diff) | |
download | rails-d99c790f65204520690c20f5789148f3c7e2bce8.tar.gz rails-d99c790f65204520690c20f5789148f3c7e2bce8.tar.bz2 rails-d99c790f65204520690c20f5789148f3c7e2bce8.zip |
split subscribers based on pattern type
Diffstat (limited to 'activesupport/lib/active_support/notifications')
-rw-r--r-- | activesupport/lib/active_support/notifications/fanout.rb | 44 |
1 files changed, 31 insertions, 13 deletions
diff --git a/activesupport/lib/active_support/notifications/fanout.rb b/activesupport/lib/active_support/notifications/fanout.rb index 4c1b7b2784..bb1111e0c2 100644 --- a/activesupport/lib/active_support/notifications/fanout.rb +++ b/activesupport/lib/active_support/notifications/fanout.rb @@ -9,7 +9,7 @@ module ActiveSupport end def subscribe(pattern = nil, block = Proc.new) - subscriber = Subscriber.new(pattern, block) + subscriber = Subscribers.new pattern, block @subscribers << subscriber @listeners_for.clear subscriber @@ -36,23 +36,41 @@ module ActiveSupport def wait end - class Subscriber #:nodoc: - def initialize(pattern, delegate) - @pattern = pattern - @delegate = delegate + module Subscribers # :nodoc: + def self.new(pattern, block) + if pattern + Subscriber.new pattern, block + else + AllMessages.new pattern, block + end end - def publish(message, *args) - @delegate.call(message, *args) - end + class Subscriber #:nodoc: + def initialize(pattern, delegate) + @pattern = pattern + @delegate = delegate + end + + def publish(message, *args) + @delegate.call(message, *args) + end - def subscribed_to?(name) - !@pattern || @pattern === name.to_s + def subscribed_to?(name) + @pattern === name.to_s + end + + def matches?(subscriber_or_name) + self === subscriber_or_name || + @pattern && @pattern === subscriber_or_name + end end - def matches?(subscriber_or_name) - self === subscriber_or_name || - @pattern && @pattern === subscriber_or_name + class AllMessages < Subscriber # :nodoc: + def subscribed_to?(name) + true + end + + alias :matches? :=== end end end |