From c1ea574b276389e565c38ff0584962afaefdeb2d Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Thu, 31 May 2012 16:58:17 +0900 Subject: improve readability of AR explain result --- activerecord/lib/active_record/explain.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'activerecord/lib/active_record/explain.rb') diff --git a/activerecord/lib/active_record/explain.rb b/activerecord/lib/active_record/explain.rb index 313fdb3487..832b34a37e 100644 --- a/activerecord/lib/active_record/explain.rb +++ b/activerecord/lib/active_record/explain.rb @@ -52,7 +52,7 @@ module ActiveRecord # Makes the adapter execute EXPLAIN for the tuples of queries and bindings. # Returns a formatted string ready to be logged. def exec_explain(queries) # :nodoc: - queries && queries.map do |sql, bind| + str = queries && queries.map do |sql, bind| [].tap do |msg| msg << "EXPLAIN for: #{sql}" unless bind.empty? @@ -62,6 +62,12 @@ module ActiveRecord msg << connection.explain(sql, bind) end.join("\n") end.join("\n") + + # overriding inspect to be more human readable + def str.inspect + self + end + str end # Silences automatic EXPLAIN logging for the duration of the block. -- cgit v1.2.3