activerecord-analyze 0.7.1 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b2021239ed9352a040106ce8c1de50503e785fccd9a3093928eeaf5dfa79a0dc
4
- data.tar.gz: 8ba00244e759dc1f31091ec4196aded3887c9007902faf867431ea2ef9ae93dc
3
+ metadata.gz: 125c8ead9447324802fcd4cd6c32c890aecf46c98f6efb3b41ab21d1a51afedd
4
+ data.tar.gz: f7314c778b981e2e9ddc89a737d5a24155ed99bd77a9c94a7e350e33b8002d05
5
5
  SHA512:
6
- metadata.gz: ad2874f8422dc7299b8b7b3036fbec8e90f29780862ea3dd192629894905aafede52731314cc569afb6c9ce31f61a379b31ac308af0c304fc9e72bea583e58a7
7
- data.tar.gz: 114236b8af394e3f7fad06549e3bc99fa1814e815dd93282c7d3abfc0a0535ee568d90c0360abab021c83a7f1b38d2bfd0bfec31f043720893ab321776fe83fe
6
+ metadata.gz: 9952cb78fcc8076ca6be19f697377b4ded8b2c090ba51affb04e6a6e67a1a83ad5c3900ff4fbf8ef27fa4ad491e881296156ccc79e0424f794f783c6ac050ce3
7
+ data.tar.gz: f3a1cf3d8166520a32d1ae83e1c9803500a887abd2ced53d83ddabcace23ada512e2003437d6ed93667645154fa4acf103bfca445b47698790484e8ab02f98bb
data/README.md CHANGED
@@ -36,8 +36,8 @@ You can execute it like that:
36
36
 
37
37
  ```ruby
38
38
 
39
- User.all.analyze(
40
- format: :json,
39
+ puts User.all.analyze(
40
+ format: :pretty, # :pretty format option generates a formatted JSON output
41
41
  verbose: true,
42
42
  costs: true,
43
43
  settings: true,
@@ -9,6 +9,8 @@ module ActiveRecord
9
9
  "FORMAT JSON,"
10
10
  when :hash
11
11
  "FORMAT JSON,"
12
+ when :pretty
13
+ "FORMAT JSON,"
12
14
  when :yaml
13
15
  "FORMAT YAML,"
14
16
  when :text
@@ -66,7 +68,7 @@ module ActiveRecord
66
68
  class Relation
67
69
  def analyze(opts = {})
68
70
  res = exec_analyze(collecting_queries_for_explain { exec_queries }, opts)
69
- if [:json, :hash].include?(opts[:format])
71
+ if [:json, :hash, :pretty].include?(opts[:format])
70
72
  start = res.index("[\n")
71
73
  finish = res.rindex("]")
72
74
  raw_json = res.slice(start, finish - start + 1)
@@ -75,6 +77,8 @@ module ActiveRecord
75
77
  JSON.parse(raw_json).to_json
76
78
  elsif opts[:format] == :hash
77
79
  JSON.parse(raw_json)
80
+ elsif opts[:format] == :pretty
81
+ JSON.pretty_generate(JSON.parse(raw_json))
78
82
  end
79
83
  else
80
84
  res
@@ -1,3 +1,3 @@
1
1
  module ActiveRecordAnalyze
2
- VERSION = "0.7.1"
2
+ VERSION = "0.8.0"
3
3
  end
data/spec/main_spec.rb CHANGED
@@ -41,6 +41,15 @@ describe "ActiveRecord analyze" do
41
41
  end
42
42
  end
43
43
 
44
+ describe "format pretty" do
45
+ it "works" do
46
+ result = User.all.analyze(format: :pretty)
47
+ expect(JSON.parse(result)[0].keys.sort).to eq [
48
+ "Execution Time", "Plan", "Planning Time", "Triggers"
49
+ ]
50
+ end
51
+ end
52
+
44
53
  describe "supports options" do
45
54
  it "works" do
46
55
  result = User.all.limit(10).where.not(email: nil).analyze(
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-analyze
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - pawurb
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-09 00:00:00.000000000 Z
11
+ date: 2021-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails