whoop 1.0.0 → 1.0.1
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 +4 -4
- data/Gemfile.lock +7 -1
- data/README.md +2 -2
- data/Rakefile +19 -0
- data/lib/whoop/formatters/json_formatter.rb +5 -1
- data/lib/whoop/formatters/sql_formatter.rb +34 -1
- data/lib/whoop/version.rb +1 -1
- data/lib/whoop.rb +2 -0
- data/sig/whoop.rbs +18 -5
- metadata +15 -2
- data/whoop.gemspec +0 -46
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a3377a8066ffe3e56b4c0bda3edb7763d54397116e73fb10dcfeca91c16b49f
|
4
|
+
data.tar.gz: cba013c48234104ebe5d955ecc5d838f19146985b9592297fb2b6c81725144f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 75b4c83644abbe37fc838020c324090ab233c9ccdc46c114025959a91cd7fb46c5fbfef363ce763f71c55f3f18adf3431f098d33ef768c6ecf21676bf34a1a27
|
7
|
+
data.tar.gz: e6dbb3c9e707b29f8feab0eb244d78561ae015ece90eb0c49d100c8987d10dce4035e846c43cffdc73a52905e6000ce90dbcda8b912fecaaf232dd47b29a0ad1
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
whoop (1.0.
|
4
|
+
whoop (1.0.1)
|
5
|
+
activerecord
|
5
6
|
activesupport
|
6
7
|
anbt-sql-formatter
|
7
8
|
colorize
|
@@ -10,6 +11,11 @@ PATH
|
|
10
11
|
GEM
|
11
12
|
remote: https://rubygems.org/
|
12
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)
|
13
19
|
activesupport (7.0.4)
|
14
20
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
15
21
|
i18n (>= 1.6, < 2)
|
data/README.md
CHANGED
@@ -64,7 +64,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
64
64
|
|
65
65
|
## Contributing
|
66
66
|
|
67
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
67
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/coderberry/whoop. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/coderberry/whoop/blob/main/CODE_OF_CONDUCT.md).
|
68
68
|
|
69
69
|
## License
|
70
70
|
|
@@ -72,7 +72,7 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
72
72
|
|
73
73
|
## Code of Conduct
|
74
74
|
|
75
|
-
Everyone interacting in the Whoop project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/
|
75
|
+
Everyone interacting in the Whoop project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/coderberry/whoop/blob/main/CODE_OF_CONDUCT.md).
|
76
76
|
|
77
77
|
## Attribution
|
78
78
|
|
data/Rakefile
CHANGED
@@ -4,7 +4,26 @@ require "bundler/gem_tasks"
|
|
4
4
|
require "rspec/core/rake_task"
|
5
5
|
|
6
6
|
RSpec::Core::RakeTask.new(:spec)
|
7
|
+
GEM_NAME = "whoop"
|
8
|
+
GEM_VERSION = Whoop::VERSION
|
7
9
|
|
8
10
|
require "standard/rake"
|
11
|
+
require "bump/tasks"
|
9
12
|
|
10
13
|
task default: %i[spec standard]
|
14
|
+
|
15
|
+
task :build do
|
16
|
+
system "gem build #{GEM_NAME}.gemspec"
|
17
|
+
end
|
18
|
+
|
19
|
+
task install: :build do
|
20
|
+
system "gem install #{GEM_NAME}-#{GEM_VERSION}.gem"
|
21
|
+
end
|
22
|
+
|
23
|
+
task publish: :build do
|
24
|
+
system "gem push #{GEM_NAME}-#{GEM_VERSION}.gem"
|
25
|
+
end
|
26
|
+
|
27
|
+
task :clean do
|
28
|
+
system "rm *.gem"
|
29
|
+
end
|
@@ -15,7 +15,11 @@ module Whoop
|
|
15
15
|
|
16
16
|
formatter = Rouge::Formatters::TerminalTruecolor.new
|
17
17
|
lexer = Rouge::Lexers::JSON.new
|
18
|
-
|
18
|
+
|
19
|
+
[
|
20
|
+
"json:\n\n".colorize(:light_black).underline,
|
21
|
+
formatter.format(lexer.lex(pretty_json))
|
22
|
+
].join
|
19
23
|
end
|
20
24
|
end
|
21
25
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "anbt-sql-formatter/formatter"
|
4
|
+
require "active_record"
|
4
5
|
|
5
6
|
module Whoop
|
6
7
|
module Formatters
|
@@ -16,15 +17,47 @@ module Whoop
|
|
16
17
|
|
17
18
|
formatter = Rouge::Formatters::TerminalTruecolor.new
|
18
19
|
lexer = Rouge::Lexers::SQL.new
|
19
|
-
|
20
|
+
|
21
|
+
formatted_sql = formatter.format(lexer.lex(pretty_sql))
|
22
|
+
return formatted_sql unless explain
|
23
|
+
|
24
|
+
raw_explain = exec_explain(sql)
|
25
|
+
formatted_explain = formatter.format(lexer.lex(raw_explain))
|
26
|
+
|
27
|
+
[
|
28
|
+
"sql:\n\n".colorize(:light_black).underline,
|
29
|
+
formatted_sql,
|
30
|
+
"\n\n",
|
31
|
+
"query plan:\n\n".colorize(:light_black).underline,
|
32
|
+
formatted_explain
|
33
|
+
].join
|
20
34
|
end
|
21
35
|
|
36
|
+
# Generate a pretty SQL query
|
37
|
+
# @param [String] sql The SQL query
|
38
|
+
# @return [String] The formatted SQL query
|
22
39
|
def self.generate_pretty_sql(sql)
|
23
40
|
rule = AnbtSql::Rule.new
|
24
41
|
rule.indent_string = " "
|
25
42
|
formatter = AnbtSql::Formatter.new(rule)
|
26
43
|
formatter.format(sql.dup)
|
27
44
|
end
|
45
|
+
|
46
|
+
# Execute the `EXPLAIN` query
|
47
|
+
# @param [String] sql The SQL query
|
48
|
+
# @return [String] The formatted query plan
|
49
|
+
def self.exec_explain(sql)
|
50
|
+
result = ActiveRecord::Base.connection.exec_query("EXPLAIN #{sql}")
|
51
|
+
lines = result.rows.map(&:first)
|
52
|
+
|
53
|
+
pretty_explain = []
|
54
|
+
pretty_explain += lines.map { |line| " #{line}" }
|
55
|
+
nrows = result.rows.length
|
56
|
+
rows_label = nrows == 1 ? "row" : "rows"
|
57
|
+
pretty_explain << "\n(#{nrows} #{rows_label})"
|
58
|
+
|
59
|
+
pretty_explain.join("\n")
|
60
|
+
end
|
28
61
|
end
|
29
62
|
end
|
30
63
|
end
|
data/lib/whoop/version.rb
CHANGED
data/lib/whoop.rb
CHANGED
data/sig/whoop.rbs
CHANGED
@@ -5,8 +5,11 @@
|
|
5
5
|
module Whoop
|
6
6
|
VERSION: untyped
|
7
7
|
|
8
|
-
# sord
|
9
|
-
|
8
|
+
# sord warn - Whoop::Configuration wasn't able to be resolved to a constant in this project
|
9
|
+
# Configure the logger
|
10
|
+
#
|
11
|
+
# _@return_ — The configuration object
|
12
|
+
def self.setup: () -> Whoop::Configuration
|
10
13
|
|
11
14
|
module Main
|
12
15
|
COLORS: untyped
|
@@ -89,9 +92,19 @@ module Whoop
|
|
89
92
|
# _@return_ — The formatted SQL query
|
90
93
|
def self.format: (String sql, ?colorize: bool, ?explain: bool) -> String
|
91
94
|
|
92
|
-
#
|
93
|
-
#
|
94
|
-
|
95
|
+
# Generate a pretty SQL query
|
96
|
+
#
|
97
|
+
# _@param_ `sql` — The SQL query
|
98
|
+
#
|
99
|
+
# _@return_ — The formatted SQL query
|
100
|
+
def self.generate_pretty_sql: (String sql) -> String
|
101
|
+
|
102
|
+
# Execute the `EXPLAIN` query
|
103
|
+
#
|
104
|
+
# _@param_ `sql` — The SQL query
|
105
|
+
#
|
106
|
+
# _@return_ — The formatted query plan
|
107
|
+
def self.exec_explain: (String sql) -> String
|
95
108
|
end
|
96
109
|
|
97
110
|
module JsonFormatter
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: whoop
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Berry
|
@@ -10,6 +10,20 @@ bindir: exe
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2022-09-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activerecord
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: activesupport
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -186,7 +200,6 @@ files:
|
|
186
200
|
- lib/whoop/formatters/sql_formatter.rb
|
187
201
|
- lib/whoop/version.rb
|
188
202
|
- sig/whoop.rbs
|
189
|
-
- whoop.gemspec
|
190
203
|
homepage: https://github.com/coderberry/whoop
|
191
204
|
licenses:
|
192
205
|
- MIT
|
data/whoop.gemspec
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "lib/whoop/version"
|
4
|
-
|
5
|
-
Gem::Specification.new do |spec|
|
6
|
-
spec.name = "whoop"
|
7
|
-
spec.version = Whoop::VERSION
|
8
|
-
spec.authors = ["Eric Berry"]
|
9
|
-
spec.email = ["eric@berry.sh"]
|
10
|
-
|
11
|
-
spec.summary = "A simple gem to help you whoop your logs into shape."
|
12
|
-
spec.description = spec.summary
|
13
|
-
spec.homepage = "https://github.com/coderberry/whoop"
|
14
|
-
spec.license = "MIT"
|
15
|
-
spec.required_ruby_version = ">= 2.6.0"
|
16
|
-
|
17
|
-
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
18
|
-
|
19
|
-
spec.metadata["homepage_uri"] = spec.homepage
|
20
|
-
spec.metadata["source_code_uri"] = spec.homepage
|
21
|
-
spec.metadata["changelog_uri"] = spec.homepage
|
22
|
-
|
23
|
-
# Specify which files should be added to the gem when it is released.
|
24
|
-
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
25
|
-
spec.files = Dir.chdir(__dir__) do
|
26
|
-
`git ls-files -z`.split("\x0").reject do |f|
|
27
|
-
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
|
28
|
-
end
|
29
|
-
end
|
30
|
-
spec.bindir = "exe"
|
31
|
-
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
32
|
-
spec.require_paths = ["lib"]
|
33
|
-
|
34
|
-
spec.add_dependency "activesupport"
|
35
|
-
spec.add_dependency "anbt-sql-formatter"
|
36
|
-
spec.add_dependency "colorize"
|
37
|
-
spec.add_dependency "rouge"
|
38
|
-
|
39
|
-
spec.add_development_dependency "magic_frozen_string_literal"
|
40
|
-
spec.add_development_dependency "pry-byebug"
|
41
|
-
spec.add_development_dependency "rspec"
|
42
|
-
spec.add_development_dependency "rake"
|
43
|
-
spec.add_development_dependency "standard"
|
44
|
-
spec.add_development_dependency "bump"
|
45
|
-
spec.add_development_dependency "sord"
|
46
|
-
end
|