aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2012-03-21 15:04:22 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2012-03-21 16:18:47 -0700
commitc7847f14fde3263fc06e0bad8448949848163d0d (patch)
treef856e692a3116389e215bff0dd780f20b2c130d1
parent6989db9238446838448d8974f6e0934161bd95b9 (diff)
downloadrails-c7847f14fde3263fc06e0bad8448949848163d0d.tar.gz
rails-c7847f14fde3263fc06e0bad8448949848163d0d.tar.bz2
rails-c7847f14fde3263fc06e0bad8448949848163d0d.zip
evented listeners can subscribe to any message
-rw-r--r--activesupport/lib/active_support/notifications/fanout.rb36
1 files changed, 27 insertions, 9 deletions
diff --git a/activesupport/lib/active_support/notifications/fanout.rb b/activesupport/lib/active_support/notifications/fanout.rb
index 40d7501e1b..17c99089c1 100644
--- a/activesupport/lib/active_support/notifications/fanout.rb
+++ b/activesupport/lib/active_support/notifications/fanout.rb
@@ -47,17 +47,19 @@ module ActiveSupport
module Subscribers # :nodoc:
def self.new(pattern, listener)
if listener.respond_to?(:call)
- if pattern
- TimedSubscriber.new pattern, listener
- else
- AllMessages.new pattern, listener
- end
+ subscriber = Timed.new pattern, listener
else
- Subscriber.new pattern, listener
+ subscriber = Evented.new pattern, listener
+ end
+
+ unless pattern
+ AllMessages.new(subscriber)
+ else
+ subscriber
end
end
- class Subscriber #:nodoc:
+ class Evented #:nodoc:
def initialize(pattern, delegate)
@pattern = pattern
@delegate = delegate
@@ -81,7 +83,7 @@ module ActiveSupport
end
end
- class TimedSubscriber < Subscriber
+ class Timed < Evented
def initialize(pattern, delegate)
@timestack = Hash.new { |h,id|
h[id] = Hash.new { |ids,name| ids[name] = [] }
@@ -103,7 +105,23 @@ module ActiveSupport
end
end
- class AllMessages < TimedSubscriber # :nodoc:
+ class AllMessages # :nodoc:
+ def initialize(delegate)
+ @delegate = delegate
+ end
+
+ def start(name, id, payload)
+ @delegate.start name, id, payload
+ end
+
+ def finish(name, id, payload)
+ @delegate.finish name, id, payload
+ end
+
+ def publish(name, *args)
+ @delegate.publish name, *args
+ end
+
def subscribed_to?(name)
true
end