Skip to content

Commit

Permalink
improve readability of AR explain result
Browse files Browse the repository at this point in the history
  • Loading branch information
amatsuda committed Jun 1, 2012
1 parent 47896d2 commit c1ea574
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion activerecord/lib/active_record/explain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def collecting_queries_for_explain # :nodoc:
# 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?
Expand All @@ -62,6 +62,12 @@ def exec_explain(queries) # :nodoc:
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.
Expand Down

0 comments on commit c1ea574

Please sign in to comment.