diff options
author | Matthew Draper <matthew@trebex.net> | 2014-06-03 01:41:57 +0930 |
---|---|---|
committer | Matthew Draper <matthew@trebex.net> | 2014-06-03 01:41:57 +0930 |
commit | 38454bb2666ca7d258a4ca2b53e16bcc3a2ee019 (patch) | |
tree | 538df1aca4c55d2e62d84e17170274ad91f34c3c | |
parent | 14a1cb7b6880a95af739b992c5c7248d858941f2 (diff) | |
parent | a8439bc470e90cce44fef6c182d94cf01a944f1e (diff) | |
download | rails-38454bb2666ca7d258a4ca2b53e16bcc3a2ee019.tar.gz rails-38454bb2666ca7d258a4ca2b53e16bcc3a2ee019.tar.bz2 rails-38454bb2666ca7d258a4ca2b53e16bcc3a2ee019.zip |
Merge pull request #15464 from tgxworld/improve_notifications_logic
Improvements to ActiveSupport::Notifications.
-rw-r--r-- | activesupport/lib/active_support/notifications.rb | 9 | ||||
-rw-r--r-- | activesupport/lib/active_support/notifications/fanout.rb | 17 |
2 files changed, 18 insertions, 8 deletions
diff --git a/activesupport/lib/active_support/notifications.rb b/activesupport/lib/active_support/notifications.rb index 7a96c66626..325a3d75dc 100644 --- a/activesupport/lib/active_support/notifications.rb +++ b/activesupport/lib/active_support/notifications.rb @@ -141,6 +141,11 @@ module ActiveSupport # # ActiveSupport::Notifications.unsubscribe(subscriber) # + # You can also unsubscribe by passing the name of the subscriber object. Note + # that this will unsubscribe all subscriptions with the given name: + # + # ActiveSupport::Notifications.unsubscribe("render") + # # == Default Queue # # Notifications ships with a queue implementation that consumes and publishes events @@ -173,8 +178,8 @@ module ActiveSupport unsubscribe(subscriber) end - def unsubscribe(args) - notifier.unsubscribe(args) + def unsubscribe(subscriber_or_name) + notifier.unsubscribe(subscriber_or_name) end def instrumenter diff --git a/activesupport/lib/active_support/notifications/fanout.rb b/activesupport/lib/active_support/notifications/fanout.rb index 8f5fa646e8..6bf8c7d5de 100644 --- a/activesupport/lib/active_support/notifications/fanout.rb +++ b/activesupport/lib/active_support/notifications/fanout.rb @@ -25,9 +25,15 @@ module ActiveSupport subscriber end - def unsubscribe(subscriber) + def unsubscribe(subscriber_or_name) synchronize do - @subscribers.reject! { |s| s.matches?(subscriber) } + case subscriber_or_name + when String + @subscribers.reject! { |s| s.matches?(subscriber_or_name) } + else + @subscribers.delete(subscriber_or_name) + end + @listeners_for.clear end end @@ -97,12 +103,11 @@ module ActiveSupport end def subscribed_to?(name) - @pattern === name.to_s + @pattern === name end - def matches?(subscriber_or_name) - self === subscriber_or_name || - @pattern && @pattern === subscriber_or_name + def matches?(name) + @pattern && @pattern === name end end |