diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-05-16 21:13:34 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-05-16 21:13:34 -0300 |
commit | fd119467b66d98de98d8d128382ba551c5d7a3fa (patch) | |
tree | 1693368a6ef286dad309488aff18b174d4fb3f0b /activesupport/lib/active_support | |
parent | a9ebfc0f6a1b7a54a425887b9d1a37b08633666b (diff) | |
parent | b50468d13dfc5d9ba1abe9b097d80b0191f6933f (diff) | |
download | rails-fd119467b66d98de98d8d128382ba551c5d7a3fa.tar.gz rails-fd119467b66d98de98d8d128382ba551c5d7a3fa.tar.bz2 rails-fd119467b66d98de98d8d128382ba551c5d7a3fa.zip |
Merge pull request #15037 from roccoblues/fix_duplicate_activesupport_subscribers
Fixed duplicate subscribers in ActiveSupport::Subscriber
Conflicts:
activesupport/CHANGELOG.md
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r-- | activesupport/lib/active_support/subscriber.rb | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/subscriber.rb b/activesupport/lib/active_support/subscriber.rb index 4b9b48539f..98be78b41b 100644 --- a/activesupport/lib/active_support/subscriber.rb +++ b/activesupport/lib/active_support/subscriber.rb @@ -64,12 +64,21 @@ module ActiveSupport def add_event_subscriber(event) return if %w{ start finish }.include?(event.to_s) - notifier.subscribe("#{event}.#{namespace}", subscriber) + pattern = "#{event}.#{namespace}" + + # don't add multiple subscribers (eg. if methods are redefined) + return if subscriber.patterns.include?(pattern) + + subscriber.patterns << pattern + notifier.subscribe(pattern, subscriber) end end + attr_reader :patterns # :nodoc: + def initialize @queue_key = [self.class.name, object_id].join "-" + @patterns = [] super end |