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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 56c4c714a20db32a1617afa074c9d3e2f7986b53be0351b5a17a38733731d4e7
4
- data.tar.gz: d7f77249ff127d6396aef49e9ba7aab123ee7a1fd84439e092e206112b5a1452
3
+ metadata.gz: 14ea1ca1cb59b84b95fd69a46d6e3e9e48a5b518147b5728e8c63fd0e1110a65
4
+ data.tar.gz: 9eb139f7f5537f92e8f4d0b37ad15994f1dfe5f51d39b9d07b2f7e26e4915354
5
5
  SHA512:
6
- metadata.gz: 290ace1cf7e19ebf5c8de2d3288f482d6159370cae8e3cedd5bf529864fe3b9bd7f4ee604776e40fd209a3e2ebd462013a1a6d6d9c666858011a33c1692f99e6
7
- data.tar.gz: 7a758d0fd946e3392c618fbecf72fb200a2b9451fb3c4a1081f7b488002f820879076d1ec3ba68786b25e7badb6f0bafbef9e355c3026c3efbf323572f8ec2ec
6
+ metadata.gz: a2c485ee67296ca11b5f0e55ee7794faa4397a621d9b2e12df34aa9643a4f25e43d4341a89037d176b9e59f28f5780fd20812bcf1c68a1a5d50c09e9fb338504
7
+ data.tar.gz: 383fdbde395e7a0fbde65b247e38736d5a1e3de3858973c26bc3320e50cc92057275d10c9fa4ef249f5afd895d9f4d9815846aa092a4b836d4d5ea68af091ec7
@@ -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 = []
@@ -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
@@ -1,3 +1,3 @@
1
1
  module SqlTracker
2
- VERSION = '1.3.0'.freeze
2
+ VERSION = '1.3.1'.freeze
3
3
  end
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.0
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-03-22 00:00:00.000000000 Z
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