Class: ActiveRecord::Relation
- Inherits:
-
Object
- Object
- ActiveRecord::Relation
- Defined in:
- lib/activerecord-analyze/main.rb
Instance Method Summary collapse
Instance Method Details
#analyze(opts = {}) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/activerecord-analyze/main.rb', line 67 def analyze(opts = {}) res = exec_analyze(collecting_queries_for_explain { exec_queries }, opts) if [:json, :hash].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) end else res end end |