Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

split subscribers based on pattern type

  • Loading branch information...
commit d99c790f65204520690c20f5789148f3c7e2bce8 1 parent 14b2cf6
@tenderlove tenderlove authored
Showing with 31 additions and 13 deletions.
  1. +31 −13 activesupport/lib/active_support/notifications/fanout.rb
View
44 activesupport/lib/active_support/notifications/fanout.rb
@@ -9,7 +9,7 @@ def initialize
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 @@ def listening?(name)
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
Please sign in to comment.
Something went wrong with that request. Please try again.