69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/activerecord-analyze/main.rb', line 69
def analyze(opts = {})
res = exec_analyze(collecting_queries_for_explain { exec_queries }, opts)
if [:json, :hash, :pretty].include?(opts[:format])
start = res.index("[\n")
finish = res.rindex("]")
raw_json = res.slice(start, finish - start + 1)
if opts[:format] == :json
JSON.parse(raw_json).to_json
elsif opts[:format] == :hash
JSON.parse(raw_json)
elsif opts[:format] == :pretty
JSON.pretty_generate(JSON.parse(raw_json))
end
else
res
end
end
|