From dcb13470991539ab581e02670738900c39976ff4 Mon Sep 17 00:00:00 2001 From: John Hawthorn Date: Mon, 25 Feb 2019 14:43:30 -0800 Subject: Improve Template#inspect output (#35407) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Don't call inspect from identifier_method_name * Add locals Template#inspect Handler, formats, and variant are usually obvious from looking at the identifier. However it's not uncommon to have different locals for the same template so we should make that obvious in inspect. * Add tests for short_identifier and inspect [John Hawthorn + Rafael Mendonça França] --- actionview/lib/action_view/template.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'actionview/lib/action_view') diff --git a/actionview/lib/action_view/template.rb b/actionview/lib/action_view/template.rb index cc5e0cbb4f..ca387e9229 100644 --- a/actionview/lib/action_view/template.rb +++ b/actionview/lib/action_view/template.rb @@ -203,8 +203,12 @@ module ActionView end end + def short_identifier + @short_identifier ||= defined?(Rails.root) ? identifier.sub("#{Rails.root}/", "") : identifier + end + def inspect - @inspect ||= defined?(Rails.root) ? identifier.sub("#{Rails.root}/", "") : identifier + "#<#{self.class.name} #{short_identifier} locals=#{@locals.inspect}>" end # This method is responsible for properly setting the encoding of the @@ -378,7 +382,7 @@ module ActionView end def identifier_method_name - inspect.tr("^a-z_", "_") + short_identifier.tr("^a-z_", "_") end def instrument(action, &block) # :doc: -- cgit v1.2.3