Skip to content

Commit

Permalink
just use an attr_accessor so we do not pay ||= on every notification …
Browse files Browse the repository at this point in the history
…call
  • Loading branch information
tenderlove committed Feb 9, 2011
1 parent e50d43a commit 3e02b37
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
8 changes: 3 additions & 5 deletions activesupport/lib/active_support/notifications.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ module Notifications
@instrumenters = Hash.new { |h,k| h[k] = notifier.listening?(k) }

class << self
attr_writer :notifier
attr_accessor :notifier

def publish(name, *args)
notifier.publish(name, *args)
Expand All @@ -69,13 +69,11 @@ def unsubscribe(*args)
@instrumenters.clear
end

def notifier
@notifier ||= Fanout.new
end

def instrumenter
Thread.current[:"instrumentation_#{notifier.object_id}"] ||= Instrumenter.new(notifier)
end
end

self.notifier = Fanout.new
end
end
9 changes: 7 additions & 2 deletions activesupport/test/notifications_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@
module Notifications
class TestCase < ActiveSupport::TestCase
def setup
ActiveSupport::Notifications.notifier = nil
@notifier = ActiveSupport::Notifications.notifier
@old_notifier = ActiveSupport::Notifications.notifier
@notifier = ActiveSupport::Notifications::Fanout.new
ActiveSupport::Notifications.notifier = @notifier
@events = []
@named_events = []
@subscription = @notifier.subscribe { |*args| @events << event(*args) }
@named_subscription = @notifier.subscribe("named.subscription") { |*args| @named_events << event(*args) }
end

def teardown
ActiveSupport::Notifications.notifier = @old_notifier
end

private

def event(*args)
Expand Down

0 comments on commit 3e02b37

Please sign in to comment.