whoop 1.0.0 → 1.0.2

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: 83de2300eaec2004c4bc867fef14a91689222018eee43b12fab6b9a29d425e5a
4
- data.tar.gz: 0c3c9b1d21fede7bccf827a73e8c6c3d11b6ddeb6837a4444d664687c03583f7
3
+ metadata.gz: c210634d7bf20b36da58aaaac74e882303f4336774eec34ecd7bf9759855827b
4
+ data.tar.gz: d3bc51f178779de13a22e6e79b2e42cb3c80356657d7f5c11b4973e5dce3a809
5
5
  SHA512:
6
- metadata.gz: 65ad2d5801a70c8d1dec7d7291bfa0c1fef3d2d181e6a1abb75ab41a8e9dd3e0b3550a2a51ddc58880c541838c2b6f603532a134bbbfe8ee633e66103aef0cbb
7
- data.tar.gz: 3a1662b1192c5d1828ff8a7cb7bdf5914b4e4fc1313dd23ccf38e9460cd5c8e8187e1c6a3fe695c2e3552ef04b654cb3effdc28794731f12364c3c078c25772e
6
+ metadata.gz: c9d27fa6de48e6e61588d296dee684a6a87b22586541f8a10329c29b126fe2f0a59224c8174cc4a9514ab49155ff5f082457a656c4addb2be0db51f1f0dada19
7
+ data.tar.gz: 714ad58469426ae297bb3733daff3bb62256db471b653ecbef069bc906caf32ff01e4fe7413fdb6a20536cdbdd0b5e50b1c649122ab231d33477aeaa0b9c96b5
data/Gemfile.lock CHANGED
@@ -1,8 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- whoop (1.0.0)
5
- activesupport
4
+ whoop (1.0.2)
5
+ activerecord (>= 6.1.4)
6
+ activesupport (>= 6.1.4)
6
7
  anbt-sql-formatter
7
8
  colorize
8
9
  rouge
@@ -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/[USERNAME]/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/[USERNAME]/whoop/blob/main/CODE_OF_CONDUCT.md).
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/[USERNAME]/whoop/blob/main/CODE_OF_CONDUCT.md).
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
- formatter.format(lexer.lex(pretty_json))
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
- formatter.format(lexer.lex(pretty_sql))
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Whoop
4
- VERSION = "1.0.0"
4
+ VERSION = "1.0.2"
5
5
  end
data/lib/whoop.rb CHANGED
@@ -19,6 +19,8 @@ module Whoop
19
19
  mattr_accessor :level
20
20
  @@level = :debug
21
21
 
22
+ # Configure the logger
23
+ # @yield [Whoop::Configuration] The configuration object
22
24
  def self.setup
23
25
  yield(self)
24
26
  end
data/sig/whoop.rbs CHANGED
@@ -6,7 +6,8 @@ module Whoop
6
6
  VERSION: untyped
7
7
 
8
8
  # sord omit - no YARD return type given, using untyped
9
- def self.setup: () ?{ (Whoop _self) -> void } -> untyped
9
+ # Configure the logger
10
+ def self.setup: () -> untyped
10
11
 
11
12
  module Main
12
13
  COLORS: untyped
@@ -89,9 +90,19 @@ module Whoop
89
90
  # _@return_ — The formatted SQL query
90
91
  def self.format: (String sql, ?colorize: bool, ?explain: bool) -> String
91
92
 
92
- # sord omit - no YARD type given for "sql", using untyped
93
- # sord omit - no YARD return type given, using untyped
94
- def self.generate_pretty_sql: (untyped sql) -> untyped
93
+ # Generate a pretty SQL query
94
+ #
95
+ # _@param_ `sql` The SQL query
96
+ #
97
+ # _@return_ — The formatted SQL query
98
+ def self.generate_pretty_sql: (String sql) -> String
99
+
100
+ # Execute the `EXPLAIN` query
101
+ #
102
+ # _@param_ `sql` — The SQL query
103
+ #
104
+ # _@return_ — The formatted query plan
105
+ def self.exec_explain: (String sql) -> String
95
106
  end
96
107
 
97
108
  module JsonFormatter
data/whoop.gemspec CHANGED
@@ -31,7 +31,8 @@ Gem::Specification.new do |spec|
31
31
  spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
32
32
  spec.require_paths = ["lib"]
33
33
 
34
- spec.add_dependency "activesupport"
34
+ spec.add_dependency "activerecord", ">= 6.1.4"
35
+ spec.add_dependency "activesupport", ">= 6.1.4"
35
36
  spec.add_dependency "anbt-sql-formatter"
36
37
  spec.add_dependency "colorize"
37
38
  spec.add_dependency "rouge"
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.0
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Berry
@@ -10,20 +10,34 @@ 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: 6.1.4
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 6.1.4
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: activesupport
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
31
  - - ">="
18
32
  - !ruby/object:Gem::Version
19
- version: '0'
33
+ version: 6.1.4
20
34
  type: :runtime
21
35
  prerelease: false
22
36
  version_requirements: !ruby/object:Gem::Requirement
23
37
  requirements:
24
38
  - - ">="
25
39
  - !ruby/object:Gem::Version
26
- version: '0'
40
+ version: 6.1.4
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: anbt-sql-formatter
29
43
  requirement: !ruby/object:Gem::Requirement