whoop 1.0.3 → 1.1.0

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: e87afc662b392a97fb44f20ec959efbd381c610d79632078feb9fca40f2591c9
4
- data.tar.gz: 4710ad20b1dd68ee4215b964767ccb4ad82a863dfa720c6569735be37b03e89d
3
+ metadata.gz: 81bf8fe803a7a41184c6bf4600abc8059665bbc040d621b3cc39235915d0c80a
4
+ data.tar.gz: 54f408ce9613144520e6b318af06353d61e997a3891e4c315e712da1b6208159
5
5
  SHA512:
6
- metadata.gz: 636d9da4424c22bda6c608a69b2bf4e4685b04698a2c960dbafcd479cc4cfe4129512b59bda6055a90745b3be534be31e9f195481353ead1707b9bc468575e1c
7
- data.tar.gz: af6eb8555456810f4d3c9a63a06b7f6337c6abd63ea004907618752465435c82f9c6857c7f95e7ff8a8d50646fc01e5c8709ed0091c1f8f8f793bf35dd75b668
6
+ metadata.gz: b6be592483ea7056091c04733bba3d5c6642f1b28aa52ef2837d07db13c8c555157fce39effb6055c2c3473c2d536db546eebb52e001fcff81837641c02fe5fe
7
+ data.tar.gz: fbad092eb0aca584c4668df1b1682d948d6b67104e14763b3f884019efdf1ba79b6ee6b2c51290defc9dbee4f4c41d01147c5f88c20c2eda27424d21e96816ae
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- whoop (1.0.3)
4
+ whoop (1.1.0)
5
5
  activerecord (>= 6.1.4)
6
6
  activesupport (>= 6.1.4)
7
7
  anbt-sql-formatter
@@ -11,12 +11,12 @@ PATH
11
11
  GEM
12
12
  remote: https://rubygems.org/
13
13
  specs:
14
- activemodel (7.0.4)
15
- activesupport (= 7.0.4)
16
- activerecord (7.0.4)
17
- activemodel (= 7.0.4)
18
- activesupport (= 7.0.4)
19
- activesupport (7.0.4)
14
+ activemodel (7.0.4.3)
15
+ activesupport (= 7.0.4.3)
16
+ activerecord (7.0.4.3)
17
+ activemodel (= 7.0.4.3)
18
+ activesupport (= 7.0.4.3)
19
+ activesupport (7.0.4.3)
20
20
  concurrent-ruby (~> 1.0, >= 1.0.2)
21
21
  i18n (>= 1.6, < 2)
22
22
  minitest (>= 5.1)
@@ -31,25 +31,26 @@ GEM
31
31
  colorize (0.8.1)
32
32
  commander (4.6.0)
33
33
  highline (~> 2.0.0)
34
- concurrent-ruby (1.1.10)
34
+ concurrent-ruby (1.2.2)
35
35
  diff-lcs (1.5.0)
36
36
  docile (1.4.0)
37
37
  highline (2.0.3)
38
38
  i18n (1.12.0)
39
39
  concurrent-ruby (~> 1.0)
40
- json (2.6.2)
40
+ json (2.6.3)
41
+ language_server-protocol (3.17.0.3)
41
42
  magic_frozen_string_literal (1.2.0)
42
43
  method_source (1.0.0)
43
- minitest (5.16.3)
44
+ minitest (5.18.0)
44
45
  parallel (1.22.1)
45
46
  parlour (5.0.0)
46
47
  commander (~> 4.5)
47
48
  parser
48
49
  rainbow (~> 3.0)
49
50
  sorbet-runtime (>= 0.5)
50
- parser (3.1.2.1)
51
+ parser (3.2.2.0)
51
52
  ast (~> 2.4.1)
52
- pry (0.14.1)
53
+ pry (0.14.2)
53
54
  coderay (~> 1.1)
54
55
  method_source (~> 1.0)
55
56
  pry-byebug (3.10.1)
@@ -57,61 +58,62 @@ GEM
57
58
  pry (>= 0.13, < 0.15)
58
59
  rainbow (3.1.1)
59
60
  rake (13.0.6)
60
- regexp_parser (2.5.0)
61
+ rbs (2.8.4)
62
+ regexp_parser (2.8.0)
61
63
  rexml (3.2.5)
62
- rouge (4.0.0)
63
- rspec (3.11.0)
64
- rspec-core (~> 3.11.0)
65
- rspec-expectations (~> 3.11.0)
66
- rspec-mocks (~> 3.11.0)
67
- rspec-core (3.11.0)
68
- rspec-support (~> 3.11.0)
69
- rspec-expectations (3.11.0)
64
+ rouge (4.1.0)
65
+ rspec (3.12.0)
66
+ rspec-core (~> 3.12.0)
67
+ rspec-expectations (~> 3.12.0)
68
+ rspec-mocks (~> 3.12.0)
69
+ rspec-core (3.12.1)
70
+ rspec-support (~> 3.12.0)
71
+ rspec-expectations (3.12.2)
70
72
  diff-lcs (>= 1.2.0, < 2.0)
71
- rspec-support (~> 3.11.0)
72
- rspec-mocks (3.11.1)
73
+ rspec-support (~> 3.12.0)
74
+ rspec-mocks (3.12.5)
73
75
  diff-lcs (>= 1.2.0, < 2.0)
74
- rspec-support (~> 3.11.0)
75
- rspec-support (3.11.0)
76
- rubocop (1.35.1)
76
+ rspec-support (~> 3.12.0)
77
+ rspec-support (3.12.0)
78
+ rubocop (1.48.1)
77
79
  json (~> 2.3)
78
80
  parallel (~> 1.10)
79
- parser (>= 3.1.2.1)
81
+ parser (>= 3.2.0.0)
80
82
  rainbow (>= 2.2.2, < 4.0)
81
83
  regexp_parser (>= 1.8, < 3.0)
82
84
  rexml (>= 3.2.5, < 4.0)
83
- rubocop-ast (>= 1.20.1, < 2.0)
85
+ rubocop-ast (>= 1.26.0, < 2.0)
84
86
  ruby-progressbar (~> 1.7)
85
- unicode-display_width (>= 1.4.0, < 3.0)
86
- rubocop-ast (1.21.0)
87
- parser (>= 3.1.1.0)
88
- rubocop-performance (1.14.3)
87
+ unicode-display_width (>= 2.4.0, < 3.0)
88
+ rubocop-ast (1.28.0)
89
+ parser (>= 3.2.1.0)
90
+ rubocop-performance (1.16.0)
89
91
  rubocop (>= 1.7.0, < 2.0)
90
92
  rubocop-ast (>= 0.4.0)
91
- ruby-progressbar (1.11.0)
92
- simplecov (0.16.1)
93
+ ruby-progressbar (1.13.0)
94
+ simplecov (0.21.2)
93
95
  docile (~> 1.1)
94
- json (>= 1.8, < 3)
95
- simplecov-html (~> 0.10.0)
96
- simplecov-html (0.10.2)
97
- sorbet-runtime (0.5.10455)
98
- sord (4.0.0)
96
+ simplecov-html (~> 0.11)
97
+ simplecov_json_formatter (~> 0.1)
98
+ simplecov-html (0.12.3)
99
+ simplecov_json_formatter (0.1.4)
100
+ sorbet-runtime (0.5.10784)
101
+ sord (5.0.0)
99
102
  commander (~> 4.5)
100
103
  parlour (~> 5.0)
104
+ rbs (~> 2.0)
101
105
  sorbet-runtime
102
106
  yard
103
- standard (1.16.1)
104
- rubocop (= 1.35.1)
105
- rubocop-performance (= 1.14.3)
106
- tzinfo (2.0.5)
107
+ standard (1.26.0)
108
+ language_server-protocol (~> 3.17.0.2)
109
+ rubocop (~> 1.48.1)
110
+ rubocop-performance (~> 1.16.0)
111
+ tzinfo (2.0.6)
107
112
  concurrent-ruby (~> 1.0)
108
- unicode-display_width (2.3.0)
109
- webrick (1.7.0)
110
- yard (0.9.28)
111
- webrick (~> 1.7.0)
113
+ unicode-display_width (2.4.2)
114
+ yard (0.9.34)
112
115
 
113
116
  PLATFORMS
114
- arm64-darwin-21
115
117
  x86_64-linux
116
118
 
117
119
  DEPENDENCIES
@@ -127,4 +129,4 @@ DEPENDENCIES
127
129
  whoop!
128
130
 
129
131
  BUNDLED WITH
130
- 2.3.22
132
+ 2.4.9
@@ -0,0 +1,23 @@
1
+ module Whoop
2
+ class InstallGenerator < Rails::Generators::Base
3
+ desc "This generator creates an initializer file for the Whoop gem at config/initializers/whoop.rb, with default settings."
4
+
5
+ def install
6
+ file_contents = <<~TEXT
7
+ Whoop.setup do |config|
8
+ config.logger = ActiveSupport::Logger.new("log/debug.log")
9
+ # config.logger = ActiveSupport::Logger.new("log/\#{Rails.env}.log")
10
+ # config.logger = ActiveSupport::Logger.new($stdout)
11
+ # config.logger = nil # uses `puts`
12
+
13
+ config.level = :debug # or :info, :warn, :error
14
+ # config.level = :info
15
+ # config.level = :warn
16
+ # config.level = :error
17
+ end
18
+ TEXT
19
+
20
+ create_file "config/initializers/whoop.rb", file_contents
21
+ end
22
+ end
23
+ end
@@ -6,6 +6,33 @@ require "active_record"
6
6
  module Whoop
7
7
  module Formatters
8
8
  module SqlFormatter
9
+ # Hash of patterns to preserve in the SQL. The key is the expected pattern,
10
+ # the value is the pattern after it has been "broken" by anbt formatting.
11
+ # Instances of the value are replaced by the key.
12
+ # Patterns are jsonb column operators from https://www.postgresql.org/docs/15/functions-json.html
13
+ PATTERNS_TO_PRESERVE = {
14
+ # jsonb operators without surrounding spaces
15
+ # IE, the first one replaces " : : " with "::"
16
+ "::" => /\s?: :\s?/,
17
+ "->>" => /\s?- > >\s?/,
18
+ "->" => /\s?- >\s?/,
19
+ "#>>" => /\s?# > >\s?/,
20
+ "#>" => /\s?# >\s?/,
21
+
22
+ # jsonb operators with surrounding spaces
23
+ # IE, the first one replaces " @ > " with " @> "
24
+ " @> " => /\s?@ >\s?/,
25
+ " <@ " => /\s?< @\s?/,
26
+ " ?| " => /\s?\? \|\s?/,
27
+ " ?& " => /\s?\? &\s?/,
28
+ " || " => /\s?\| \|\s?/,
29
+ " #- " => /\s?# -\s?/,
30
+
31
+ # Additional broken patterns
32
+ "[" => /\[\s?/,
33
+ "]" => /\s?\]/
34
+ }
35
+
9
36
  # Format the SQL query
10
37
  # @param [String] sql The SQL query
11
38
  # @param [Boolean] colorize - colorize the SQL query (default: false)
@@ -39,8 +66,20 @@ module Whoop
39
66
  def self.generate_pretty_sql(sql)
40
67
  rule = AnbtSql::Rule.new
41
68
  rule.indent_string = " "
69
+
42
70
  formatter = AnbtSql::Formatter.new(rule)
43
- formatter.format(sql.dup)
71
+ formatted_string = formatter.format(sql.dup)
72
+
73
+ # Anbt injects additional spaces into joined symbols.
74
+ # This removes them by generating the "broken" collection
75
+ # of symbols, and replacing them with the original.
76
+ PATTERNS_TO_PRESERVE.each do |correct_pattern, incorrect_pattern|
77
+ next unless incorrect_pattern.match?(formatted_string)
78
+
79
+ formatted_string.gsub!(incorrect_pattern, correct_pattern)
80
+ end
81
+
82
+ formatted_string
44
83
  end
45
84
 
46
85
  # Execute the `EXPLAIN` query
@@ -53,7 +92,7 @@ module Whoop
53
92
  pretty_explain = []
54
93
  pretty_explain += lines.map { |line| " #{line}" }
55
94
  nrows = result.rows.length
56
- rows_label = nrows == 1 ? "row" : "rows"
95
+ rows_label = (nrows == 1) ? "row" : "rows"
57
96
  pretty_explain << "\n(#{nrows} #{rows_label})"
58
97
 
59
98
  pretty_explain.join("\n")
data/lib/whoop/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Whoop
4
- VERSION = "1.0.3"
4
+ VERSION = "1.1.0"
5
5
  end
data/lib/whoop.rb CHANGED
@@ -87,6 +87,7 @@ module Whoop
87
87
  logger_method.call ""
88
88
  logger_method.call formatter_method.call(result)
89
89
  logger_method.call ""
90
+ display_invalid_format_message(format, color_method, logger_method)
90
91
  logger_method.call color_method.call "#{BOTTOM_LINE_CHAR}#{line}\n\n"
91
92
  end
92
93
  else
@@ -98,6 +99,7 @@ module Whoop
98
99
  logger_method.call ""
99
100
  logger_method.call formatter_method.call(label)
100
101
  logger_method.call ""
102
+ display_invalid_format_message(format, color_method, logger_method)
101
103
  logger_method.call color_method.call "#{BOTTOM_LINE_CHAR}#{line}\n\n"
102
104
  end
103
105
  end
@@ -150,6 +152,13 @@ module Whoop
150
152
  end
151
153
  end
152
154
 
155
+ def display_invalid_format_message(format, color_method, logger_method)
156
+ return if FORMATS.include?(format)
157
+
158
+ invalid_format_line = [color_method.call(INDENT), "note:".colorize(:blue).underline, "Unsupported format used. Available formats: #{FORMATS.to_sentence}"].join(" ")
159
+ logger_method.call invalid_format_line
160
+ end
161
+
153
162
  # Return the line with the label centered in it
154
163
  # @param [String] label
155
164
  # @param [Integer] count
data/sig/whoop.rbs CHANGED
@@ -73,6 +73,12 @@ module Whoop
73
73
  # _@return_ — format method
74
74
  def detect_formatter_method: (Symbol format, ?colorize: untyped, ?explain: untyped) -> Method
75
75
 
76
+ # sord omit - no YARD type given for "format", using untyped
77
+ # sord omit - no YARD type given for "color_method", using untyped
78
+ # sord omit - no YARD type given for "logger_method", using untyped
79
+ # sord omit - no YARD return type given, using untyped
80
+ def display_invalid_format_message: (untyped format, untyped color_method, untyped logger_method) -> untyped
81
+
76
82
  # Return the line with the label centered in it
77
83
  #
78
84
  # _@param_ `label`
@@ -85,6 +91,8 @@ module Whoop
85
91
 
86
92
  module Formatters
87
93
  module SqlFormatter
94
+ PATTERNS_TO_PRESERVE: untyped
95
+
88
96
  # Format the SQL query
89
97
  #
90
98
  # _@param_ `sql` — The SQL query
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: whoop
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Berry
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-10-03 00:00:00.000000000 Z
11
+ date: 2023-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -222,6 +222,7 @@ files:
222
222
  - LICENSE.txt
223
223
  - README.md
224
224
  - Rakefile
225
+ - lib/generators/whoop/install_generator.rb
225
226
  - lib/whoop.rb
226
227
  - lib/whoop/formatters/json_formatter.rb
227
228
  - lib/whoop/formatters/sql_formatter.rb
@@ -235,7 +236,7 @@ metadata:
235
236
  homepage_uri: https://github.com/coderberry/whoop
236
237
  source_code_uri: https://github.com/coderberry/whoop
237
238
  changelog_uri: https://github.com/coderberry/whoop
238
- post_install_message:
239
+ post_install_message:
239
240
  rdoc_options: []
240
241
  require_paths:
241
242
  - lib
@@ -250,8 +251,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
250
251
  - !ruby/object:Gem::Version
251
252
  version: '0'
252
253
  requirements: []
253
- rubygems_version: 3.3.7
254
- signing_key:
254
+ rubygems_version: 3.4.6
255
+ signing_key:
255
256
  specification_version: 4
256
257
  summary: A simple gem to help you whoop your logs into shape.
257
258
  test_files: []