whoop 1.0.3 → 1.0.4

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: a9b6642d169f36ac114748f02515b804646a7981f244475c41fa053456d93c08
4
+ data.tar.gz: ca2a36f9da6922d998189ea808bd3976684e3cf2919fb7c4ed9672408591fce7
5
5
  SHA512:
6
- metadata.gz: 636d9da4424c22bda6c608a69b2bf4e4685b04698a2c960dbafcd479cc4cfe4129512b59bda6055a90745b3be534be31e9f195481353ead1707b9bc468575e1c
7
- data.tar.gz: af6eb8555456810f4d3c9a63a06b7f6337c6abd63ea004907618752465435c82f9c6857c7f95e7ff8a8d50646fc01e5c8709ed0091c1f8f8f793bf35dd75b668
6
+ metadata.gz: eee07b43704595c415ec3eb4e36cf5ea2b9215982d22f7f5f1d0e7e9565c408dbaa4e41f43385c79c8089f1740907c2c21d8a2bcd9b5d74f64f103433774446a
7
+ data.tar.gz: 4865c548afe2113e7218ebde457eea291f9152c3bcecae84d684581e4ad9c397b6af965668623d4f581a571062881759d5681a6475cb570f04d9571f224b8eed
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.0.2)
5
5
  activerecord (>= 6.1.4)
6
6
  activesupport (>= 6.1.4)
7
7
  anbt-sql-formatter
@@ -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
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.0.4"
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.0.4
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-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -235,7 +235,7 @@ metadata:
235
235
  homepage_uri: https://github.com/coderberry/whoop
236
236
  source_code_uri: https://github.com/coderberry/whoop
237
237
  changelog_uri: https://github.com/coderberry/whoop
238
- post_install_message:
238
+ post_install_message:
239
239
  rdoc_options: []
240
240
  require_paths:
241
241
  - lib
@@ -250,8 +250,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
250
250
  - !ruby/object:Gem::Version
251
251
  version: '0'
252
252
  requirements: []
253
- rubygems_version: 3.3.7
254
- signing_key:
253
+ rubygems_version: 3.4.6
254
+ signing_key:
255
255
  specification_version: 4
256
256
  summary: A simple gem to help you whoop your logs into shape.
257
257
  test_files: []