sql_tracker 1.3.0 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/sql_tracker +9 -2
- data/lib/sql_tracker/report.rb +2 -24
- data/lib/sql_tracker/terminal.rb +28 -0
- data/lib/sql_tracker/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 14ea1ca1cb59b84b95fd69a46d6e3e9e48a5b518147b5728e8c63fd0e1110a65
|
4
|
+
data.tar.gz: 9eb139f7f5537f92e8f4d0b37ad15994f1dfe5f51d39b9d07b2f7e26e4915354
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a2c485ee67296ca11b5f0e55ee7794faa4397a621d9b2e12df34aa9643a4f25e43d4341a89037d176b9e59f28f5780fd20812bcf1c68a1a5d50c09e9fb338504
|
7
|
+
data.tar.gz: 383fdbde395e7a0fbde65b247e38736d5a1e3de3858973c26bc3320e50cc92057275d10c9fa4ef249f5afd895d9f4d9815846aa092a4b836d4d5ea68af091ec7
|
data/bin/sql_tracker
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
require 'sql_tracker/terminal'
|
2
3
|
require 'sql_tracker/report'
|
3
4
|
require 'json'
|
4
5
|
require 'optparse'
|
5
6
|
|
6
7
|
options = {}
|
8
|
+
default_options = { sort_by: 'count', terminal_width: SqlTracker::Terminal.width }
|
7
9
|
|
8
10
|
parser = OptionParser.new(ARGV) do |o|
|
9
11
|
o.banner = 'Usage: sql_tracker [file.json]+ [--sort-by=COLUMN]'
|
@@ -11,13 +13,18 @@ parser = OptionParser.new(ARGV) do |o|
|
|
11
13
|
o.on('-s', '--sort-by COLUMN', 'The name of column that is used for sorting the table. Options: count, duration') do |arg|
|
12
14
|
options[:sort_by] = arg if %(count duration).include?(arg)
|
13
15
|
end
|
16
|
+
|
17
|
+
o.on('-w', '--terminal-width WIDTH', Integer,
|
18
|
+
"The width of the printed report. " \
|
19
|
+
"Default: #{default_options[:terminal_width]}. " \
|
20
|
+
"Minimum #{SqlTracker::Terminal::MIN_WIDTH}") do |arg|
|
21
|
+
options[:terminal_width] = arg if arg >= SqlTracker::Terminal::MIN_WIDTH
|
22
|
+
end
|
14
23
|
end
|
15
24
|
|
16
25
|
parser.parse!
|
17
26
|
parser.abort(parser.help) if ARGV.empty?
|
18
27
|
|
19
|
-
default_options = { sort_by: 'count' }
|
20
|
-
|
21
28
|
options = default_options.merge(options)
|
22
29
|
|
23
30
|
reports = []
|
data/lib/sql_tracker/report.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module SqlTracker
|
2
2
|
class Report
|
3
3
|
attr_accessor :raw_data
|
4
|
+
attr_accessor :terminal_width
|
4
5
|
|
5
6
|
def initialize(data)
|
6
7
|
self.raw_data = data
|
@@ -26,6 +27,7 @@ module SqlTracker
|
|
26
27
|
end
|
27
28
|
|
28
29
|
def print_text(options)
|
30
|
+
self.terminal_width = options.fetch(:terminal_width)
|
29
31
|
f = STDOUT
|
30
32
|
f.puts '=================================='
|
31
33
|
f.puts "Total Unique SQL Queries: #{data.keys.size}"
|
@@ -125,29 +127,5 @@ module SqlTracker
|
|
125
127
|
def duration_width
|
126
128
|
15
|
127
129
|
end
|
128
|
-
|
129
|
-
def terminal_width
|
130
|
-
@terminal_width ||= begin
|
131
|
-
result = unix? ? dynamic_width : 80
|
132
|
-
result < 10 ? 80 : result
|
133
|
-
end
|
134
|
-
end
|
135
|
-
|
136
|
-
def dynamic_width
|
137
|
-
@dynamic_width ||= (dynamic_width_stty.nonzero? || dynamic_width_tput)
|
138
|
-
end
|
139
|
-
|
140
|
-
def dynamic_width_stty
|
141
|
-
`stty size 2>/dev/null`.split[1].to_i
|
142
|
-
end
|
143
|
-
|
144
|
-
def dynamic_width_tput
|
145
|
-
`tput cols 2>/dev/null`.to_i
|
146
|
-
end
|
147
|
-
|
148
|
-
def unix?
|
149
|
-
RUBY_PLATFORM =~
|
150
|
-
/(aix|darwin|linux|(net|free|open)bsd|cygwin|solaris|irix|hpux)/i
|
151
|
-
end
|
152
130
|
end
|
153
131
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module SqlTracker
|
2
|
+
class Terminal
|
3
|
+
DEFAULT_WIDTH = 80
|
4
|
+
MIN_WIDTH = 10
|
5
|
+
|
6
|
+
def self.width
|
7
|
+
if unix?
|
8
|
+
result = (dynamic_width_stty.nonzero? || dynamic_width_tput)
|
9
|
+
result < MIN_WIDTH ? DEFAULT_WIDTH : result
|
10
|
+
else
|
11
|
+
DEFAULT_WIDTH
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.dynamic_width_stty
|
16
|
+
`stty size 2>/dev/null`.split[1].to_i
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.dynamic_width_tput
|
20
|
+
`tput cols 2>/dev/null`.to_i
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.unix?
|
24
|
+
RUBY_PLATFORM =~
|
25
|
+
/(aix|darwin|linux|(net|free|open)bsd|cygwin|solaris|irix|hpux)/i
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/sql_tracker/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sql_tracker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steven Yue
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-05-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -88,6 +88,7 @@ files:
|
|
88
88
|
- lib/sql_tracker/handler.rb
|
89
89
|
- lib/sql_tracker/railtie.rb
|
90
90
|
- lib/sql_tracker/report.rb
|
91
|
+
- lib/sql_tracker/terminal.rb
|
91
92
|
- lib/sql_tracker/version.rb
|
92
93
|
- sql_tracker.gemspec
|
93
94
|
homepage: http://www.github.com/steventen/sql_tracker
|