From 1b7ef40db5ed06b655a624ce56c80fb91b683885 Mon Sep 17 00:00:00 2001 From: Ali Ibrahim Date: Fri, 22 Mar 2019 10:01:18 -0400 Subject: Update AS::Notifications::Instrumenter#instrument * Update #instrument to make passing a block optional. This will let users leverage #instrument for messaging in addition to instrumentation. --- activesupport/lib/active_support/notifications/instrumenter.rb | 2 +- activesupport/test/notifications/instrumenter_test.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'activesupport') diff --git a/activesupport/lib/active_support/notifications/instrumenter.rb b/activesupport/lib/active_support/notifications/instrumenter.rb index 00a57c38c9..d4e1f3ca6f 100644 --- a/activesupport/lib/active_support/notifications/instrumenter.rb +++ b/activesupport/lib/active_support/notifications/instrumenter.rb @@ -20,7 +20,7 @@ module ActiveSupport # some of the listeners might have state listeners_state = start name, payload begin - yield payload + yield payload if block_given? rescue Exception => e payload[:exception] = [e.class.name, e.message] payload[:exception_object] = e diff --git a/activesupport/test/notifications/instrumenter_test.rb b/activesupport/test/notifications/instrumenter_test.rb index d5c9e82e9f..9729ad5c89 100644 --- a/activesupport/test/notifications/instrumenter_test.rb +++ b/activesupport/test/notifications/instrumenter_test.rb @@ -44,6 +44,12 @@ module ActiveSupport assert_equal Hash[result: 2], payload end + def test_instrument_works_without_a_block + instrumenter.instrument("no.block", payload) + assert_equal 1, notifier.finishes.size + assert_equal "no.block", notifier.finishes.first.first + end + def test_start instrumenter.start("foo", payload) assert_equal [["foo", instrumenter.id, payload]], notifier.starts -- cgit v1.2.3