Skip to content

Commit cbcb947

Browse files
committed
AS::Notifications.subscribe blocks are now yielded the arguments to pass to AS::Notifications::Event.new
1 parent 9b67b7b commit cbcb947

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

actionpack/lib/action_controller/notifications.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
require 'active_support/notifications'
22

3-
ActiveSupport::Notifications.subscribe(/(read|write|cache|expire|exist)_(fragment|page)\??/) do |event|
3+
ActiveSupport::Notifications.subscribe(/(read|write|cache|expire|exist)_(fragment|page)\??/) do |*args|
4+
event = ActiveSupport::Notifications::Event.new(*args)
5+
46
if logger = ActionController::Base.logger
57
human_name = event.name.to_s.humanize
68
logger.info("#{human_name} (%.1fms)" % event.duration)

activesupport/lib/active_support/notifications.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def bind(pattern)
9696

9797
def subscribe
9898
@queue.subscribe(@pattern) do |*args|
99-
yield Event.new(*args)
99+
yield *args
100100
end
101101
end
102102
end

activesupport/test/notifications_test.rb

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ class NotificationsMainTest < Test::Unit::TestCase
5252
def setup
5353
@events = []
5454
Thread.abort_on_exception = true
55-
ActiveSupport::Notifications.subscribe { |event| @events << event }
55+
ActiveSupport::Notifications.subscribe do |*args|
56+
@events << ActiveSupport::Notifications::Event.new(*args)
57+
end
5658
end
5759

5860
def teardown
@@ -124,7 +126,11 @@ def test_event_is_pushed_even_without_block
124126

125127
def test_subscriber_with_pattern
126128
@another = []
127-
ActiveSupport::Notifications.subscribe("cache"){ |event| @another << event }
129+
130+
ActiveSupport::Notifications.subscribe("cache") do |*args|
131+
@another << ActiveSupport::Notifications::Event.new(*args)
132+
end
133+
128134
ActiveSupport::Notifications.instrument(:cache){ 1 }
129135

130136
sleep(0.1)
@@ -136,7 +142,9 @@ def test_subscriber_with_pattern
136142

137143
def test_subscriber_with_pattern_as_regexp
138144
@another = []
139-
ActiveSupport::Notifications.subscribe(/cache/){ |event| @another << event }
145+
ActiveSupport::Notifications.subscribe(/cache/) do |*args|
146+
@another << ActiveSupport::Notifications::Event.new(*args)
147+
end
140148

141149
ActiveSupport::Notifications.instrument(:something){ 0 }
142150
ActiveSupport::Notifications.instrument(:cache){ 1 }
@@ -150,7 +158,9 @@ def test_subscriber_with_pattern_as_regexp
150158

151159
def test_with_several_consumers_and_several_events
152160
@another = []
153-
ActiveSupport::Notifications.subscribe { |event| @another << event }
161+
ActiveSupport::Notifications.subscribe do |*args|
162+
@another << ActiveSupport::Notifications::Event.new(*args)
163+
end
154164

155165
1.upto(100) do |i|
156166
ActiveSupport::Notifications.instrument(:value){ i }

0 commit comments

Comments
 (0)