From 804f5b3c2af90b69a51209c56739a077f3fb632b Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Wed, 24 Aug 2016 16:01:55 -0700 Subject: kick different instrumentation method We can eliminate a conditional by calling a different instrumentation method depending on the situation. In this case, we'll call the special case "!render_template" instrumentation method and eliminate the case / when clause from the `instrument` method. --- actionview/lib/action_view/template.rb | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'actionview/lib/action_view') diff --git a/actionview/lib/action_view/template.rb b/actionview/lib/action_view/template.rb index d75457f1eb..513935cef0 100644 --- a/actionview/lib/action_view/template.rb +++ b/actionview/lib/action_view/template.rb @@ -152,7 +152,7 @@ module ActionView # we use a bang in this instrumentation because you don't want to # consume this in production. This is only slow if it's being listened to. def render(view, locals, buffer=nil, &block) - instrument("!render_template".freeze) do + instrument_render_template do compile!(view) view.send(method_name, locals, buffer, &block) end @@ -341,13 +341,17 @@ module ActionView end def instrument(action, &block) - payload = { virtual_path: @virtual_path, identifier: @identifier } - case action - when "!render_template" - ActiveSupport::Notifications.instrument("!render_template.action_view".freeze, payload, &block) - else - ActiveSupport::Notifications.instrument("#{action}.action_view".freeze, payload, &block) - end + ActiveSupport::Notifications.instrument("#{action}.action_view".freeze, instrument_payload, &block) + end + + private + + def instrument_render_template(&block) + ActiveSupport::Notifications.instrument("!render_template.action_view".freeze, instrument_payload, &block) + end + + def instrument_payload + { virtual_path: @virtual_path, identifier: @identifier } end end end -- cgit v1.2.3