whoop 0.1.0 → 1.0.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: 180b274d64d5f223c5d7db71f4ef04c701542594dbb67982b85d895fb7edda71
4
- data.tar.gz: 1ad336f0855a96251d75e095604dd618ea1c89e1cc0aadbd5e61282e2c7f143f
3
+ metadata.gz: 8a3377a8066ffe3e56b4c0bda3edb7763d54397116e73fb10dcfeca91c16b49f
4
+ data.tar.gz: cba013c48234104ebe5d955ecc5d838f19146985b9592297fb2b6c81725144f2
5
5
  SHA512:
6
- metadata.gz: 32d741be570d8fe49b229ad8bbd32cbf3120f735cea3a0fb3b4608826188490f778bd24347fe921f0d20d1529837d61554a02f82663ec75d8c33882c5f94a0a9
7
- data.tar.gz: 15bafe9cd3bcab5cec47e329e7b233cf1aadfecc367181aaefd821b7cd097aaf73793142752ce6ce01c33f0cbfdf00559e30da521975fe73d151ae65fb5833f9
6
+ metadata.gz: 75b4c83644abbe37fc838020c324090ab233c9ccdc46c114025959a91cd7fb46c5fbfef363ce763f71c55f3f18adf3431f098d33ef768c6ecf21676bf34a1a27
7
+ data.tar.gz: e6dbb3c9e707b29f8feab0eb244d78561ae015ece90eb0c49d100c8987d10dce4035e846c43cffdc73a52905e6000ce90dbcda8b912fecaaf232dd47b29a0ad1
data/Gemfile CHANGED
@@ -4,9 +4,3 @@ source "https://rubygems.org"
4
4
  git_source(:github) { |repo| "https://github.com/#{repo}.git" }
5
5
 
6
6
  gemspec
7
-
8
- gem "rspec", "~> 3.0" # minitest provides a complete suite of testing facilities supporting TDD, BDD, mocking, and benchmarking
9
- gem "organize_gemfile" # Organize your Gemfile with annotations
10
- gem "rake", "~> 13.0" # Rake is a Make-like program implemented in Ruby
11
- gem "standard", "~> 1.3" # Ruby Style Guide, with linter & automatic code fixer
12
- gem "bump", "~> 0.6" # Bump is a command line tool to help you version your Ruby projects
data/Gemfile.lock CHANGED
@@ -1,23 +1,62 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- whoop (0.1.0)
4
+ whoop (1.0.1)
5
+ activerecord
6
+ activesupport
7
+ anbt-sql-formatter
8
+ colorize
9
+ rouge
5
10
 
6
11
  GEM
7
12
  remote: https://rubygems.org/
8
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)
20
+ concurrent-ruby (~> 1.0, >= 1.0.2)
21
+ i18n (>= 1.6, < 2)
22
+ minitest (>= 5.1)
23
+ tzinfo (~> 2.0)
24
+ anbt-sql-formatter (0.1.0)
9
25
  ast (2.4.2)
10
26
  bump (0.10.0)
27
+ byebug (11.1.3)
28
+ coderay (1.1.3)
29
+ colorize (0.8.1)
30
+ commander (4.6.0)
31
+ highline (~> 2.0.0)
32
+ concurrent-ruby (1.1.10)
11
33
  diff-lcs (1.5.0)
34
+ highline (2.0.3)
35
+ i18n (1.12.0)
36
+ concurrent-ruby (~> 1.0)
12
37
  json (2.6.2)
13
- organize_gemfile (0.1.0)
38
+ magic_frozen_string_literal (1.2.0)
39
+ method_source (1.0.0)
40
+ minitest (5.16.3)
14
41
  parallel (1.22.1)
42
+ parlour (5.0.0)
43
+ commander (~> 4.5)
44
+ parser
45
+ rainbow (~> 3.0)
46
+ sorbet-runtime (>= 0.5)
15
47
  parser (3.1.2.1)
16
48
  ast (~> 2.4.1)
49
+ pry (0.14.1)
50
+ coderay (~> 1.1)
51
+ method_source (~> 1.0)
52
+ pry-byebug (3.10.1)
53
+ byebug (~> 11.0)
54
+ pry (>= 0.13, < 0.15)
17
55
  rainbow (3.1.1)
18
56
  rake (13.0.6)
19
57
  regexp_parser (2.5.0)
20
58
  rexml (3.2.5)
59
+ rouge (4.0.0)
21
60
  rspec (3.11.0)
22
61
  rspec-core (~> 3.11.0)
23
62
  rspec-expectations (~> 3.11.0)
@@ -47,20 +86,33 @@ GEM
47
86
  rubocop (>= 1.7.0, < 2.0)
48
87
  rubocop-ast (>= 0.4.0)
49
88
  ruby-progressbar (1.11.0)
89
+ sorbet-runtime (0.5.10455)
90
+ sord (4.0.0)
91
+ commander (~> 4.5)
92
+ parlour (~> 5.0)
93
+ sorbet-runtime
94
+ yard
50
95
  standard (1.16.1)
51
96
  rubocop (= 1.35.1)
52
97
  rubocop-performance (= 1.14.3)
98
+ tzinfo (2.0.5)
99
+ concurrent-ruby (~> 1.0)
53
100
  unicode-display_width (2.3.0)
101
+ webrick (1.7.0)
102
+ yard (0.9.28)
103
+ webrick (~> 1.7.0)
54
104
 
55
105
  PLATFORMS
56
106
  arm64-darwin-21
57
107
 
58
108
  DEPENDENCIES
59
- bump (~> 0.6)
60
- organize_gemfile
61
- rake (~> 13.0)
62
- rspec (~> 3.0)
63
- standard (~> 1.3)
109
+ bump
110
+ magic_frozen_string_literal
111
+ pry-byebug
112
+ rake
113
+ rspec
114
+ sord
115
+ standard
64
116
  whoop!
65
117
 
66
118
  BUNDLED WITH
data/README.md CHANGED
@@ -1,8 +1,17 @@
1
1
  # Whoop
2
2
 
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/whoop`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ [![Gem Version](https://badge.fury.io/rb/whoop.svg)](https://badge.fury.io/rb/whoop)
4
+ [![Maintainability](https://api.codeclimate.com/v1/badges/1ffd27fe59383a4ff52b/maintainability)](https://codeclimate.com/github/coderberry/whoop/maintainability)
5
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/1ffd27fe59383a4ff52b/test_coverage)](https://codeclimate.com/github/coderberry/whoop/test_coverage)
6
+ [![Tests](https://github.com/coderberry/whoop/actions/workflows/tests.yml/badge.svg)](https://github.com/coderberry/whoop/actions/workflows/tests.yml)
7
+ [![CodeQL](https://github.com/coderberry/whoop/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/coderberry/whoop/actions/workflows/codeql-analysis.yml)
8
+ [![StandardRB](https://github.com/coderberry/whoop/actions/workflows/standardrb.yml/badge.svg)](https://github.com/coderberry/whoop/actions/workflows/standardrb.yml)
9
+ [![GEM Version](https://img.shields.io/gem/v/whoop?color=168AFE&include_prereleases&logo=ruby&logoColor=FE1616)](https://rubygems.org/gems/whoop)
10
+ [![GEM Downloads](https://img.shields.io/gem/dt/whoop?color=168AFE&logo=ruby&logoColor=FE1616)](https://rubygems.org/gems/whoop)
11
+ [![Ruby Style](https://img.shields.io/badge/style-standard-168AFE?logo=ruby&logoColor=FE1616)](https://github.com/testdouble/standard)
12
+ [![Twitter Follow](https://img.shields.io/twitter/follow/coderberry?logo=twitter&style=social)](https://twitter.com/coderberry)
13
+
14
+ Whoop is a Ruby logging library with built-in formatting and colorization.
6
15
 
7
16
  ## Installation
8
17
 
@@ -14,9 +23,38 @@ If bundler is not being used to manage dependencies, install the gem by executin
14
23
 
15
24
  $ gem install whoop
16
25
 
26
+ ## Configuration
27
+
28
+ You can configure the gem for you Rails app by adding an an initializer:
29
+
30
+ ```ruby
31
+ # config/initializers/whoop.rb
32
+ Whoop.setup do |config|
33
+ config.logger = ActiveSupport::Logger.new("log/debug.log")
34
+ # config.logger = ActiveSupport::Logger.new("log/#{Rails.env}.log")
35
+ # config.logger = ActiveSupport::Logger.new($stdout)
36
+ # config.logger = nil # uses `puts`
37
+
38
+ config.level = :debug
39
+ # config.level = :info
40
+ # config.level = :warn
41
+ # config.level = :error
42
+ end
43
+ ```
44
+
17
45
  ## Usage
18
46
 
19
- TODO: Write usage instructions here
47
+ The `whoop` method is accessible from any object. See specs for more examples.
48
+
49
+ ```ruby
50
+ whoop "Hello, World!"
51
+ ```
52
+
53
+ ### Formatters
54
+ TODO
55
+
56
+ ### Colors
57
+ TODO
20
58
 
21
59
  ## Development
22
60
 
@@ -26,7 +64,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
26
64
 
27
65
  ## Contributing
28
66
 
29
- 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).
30
68
 
31
69
  ## License
32
70
 
@@ -34,4 +72,10 @@ The gem is available as open source under the terms of the [MIT License](https:/
34
72
 
35
73
  ## Code of Conduct
36
74
 
37
- 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
+
77
+ ## Attribution
78
+
79
+ This project is maintained by [Eric Berry](https://linktr.ee/coderberry).
80
+
81
+ This gem is based on the [wrapped_print](https://github.com/igorkasyanchuk/wrapped_print) gem by [Igor Kasyanchuk](https://www.railsjazz.com/).
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
data/cc-test-reporter ADDED
Binary file
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+
5
+ module Whoop
6
+ module Formatters
7
+ module JsonFormatter
8
+ # Format the SQL query
9
+ # @param [String] message The SQL query
10
+ # @param [Boolean] colorize - colorize the SQL query (default: false)
11
+ # @return [String] The formatted SQL query
12
+ def self.format(message, colorize: false)
13
+ pretty_json = JSON.pretty_generate(message)
14
+ return pretty_json unless colorize
15
+
16
+ formatter = Rouge::Formatters::TerminalTruecolor.new
17
+ lexer = Rouge::Lexers::JSON.new
18
+
19
+ [
20
+ "json:\n\n".colorize(:light_black).underline,
21
+ formatter.format(lexer.lex(pretty_json))
22
+ ].join
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "anbt-sql-formatter/formatter"
4
+ require "active_record"
5
+
6
+ module Whoop
7
+ module Formatters
8
+ module SqlFormatter
9
+ # Format the SQL query
10
+ # @param [String] sql The SQL query
11
+ # @param [Boolean] colorize - colorize the SQL query (default: false)
12
+ # @param [Boolean] explain - also run `EXPLAIN` on the query (default: false)
13
+ # @return [String] The formatted SQL query
14
+ def self.format(sql, colorize: false, explain: false)
15
+ pretty_sql = generate_pretty_sql(sql)
16
+ return pretty_sql unless colorize
17
+
18
+ formatter = Rouge::Formatters::TerminalTruecolor.new
19
+ lexer = Rouge::Lexers::SQL.new
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
34
+ end
35
+
36
+ # Generate a pretty SQL query
37
+ # @param [String] sql The SQL query
38
+ # @return [String] The formatted SQL query
39
+ def self.generate_pretty_sql(sql)
40
+ rule = AnbtSql::Rule.new
41
+ rule.indent_string = " "
42
+ formatter = AnbtSql::Formatter.new(rule)
43
+ formatter.format(sql.dup)
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
61
+ end
62
+ end
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 = "0.1.0"
4
+ VERSION = "1.0.1"
5
5
  end
data/lib/whoop.rb CHANGED
@@ -1,8 +1,140 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "active_support"
4
+ require "colorize"
5
+ require "rouge"
3
6
  require_relative "whoop/version"
7
+ require_relative "whoop/formatters/json_formatter"
8
+ require_relative "whoop/formatters/sql_formatter"
9
+
10
+ # Whoop.setup do |config|
11
+ # config.logger = ActiveSupport::Logger.new("#{Rails.root}/log/debug.log")
12
+ # config.level = :debug
13
+ # end
4
14
 
5
15
  module Whoop
6
- class Error < StandardError; end
7
- # Your code goes here...
16
+ mattr_accessor :logger
17
+ @@logger = ActiveSupport::Logger.new($stdout)
18
+
19
+ mattr_accessor :level
20
+ @@level = :debug
21
+
22
+ # Configure the logger
23
+ # @yield [Whoop::Configuration] The configuration object
24
+ def self.setup
25
+ yield(self)
26
+ end
27
+
28
+ module Main
29
+ COLORS = %i[black red green yellow blue magenta cyan white light_black light_red light_green light_yellow light_blue light_magenta light_cyan light_white default].freeze
30
+ FORMATS = %i[plain json sql].freeze
31
+ PATTERN = "-"
32
+ COUNT = 80
33
+
34
+ # Log the message to the logger
35
+ # @param [String] label (optional) - the label or object to log
36
+ # @param [String] pattern - the pattern to use for the line (e.g. '-')
37
+ # @param [Integer] count - the number of times to repeat the pattern per line (e.g. 80)
38
+ # @param [Symbol] color - the color to use for the line (e.g. :red)
39
+ # @param [Symbol] format - the format to use for the message (one of :json, :sql, :plain)
40
+ # @param [Integer] caller_depth - the depth of the caller to use for the source (default: 0)
41
+ # @param [Boolean] explain - whether to explain the SQL query (default: false)
42
+ def whoop(label = nil, pattern: PATTERN, count: COUNT, color: :default, format: :plain, caller_depth: 0, explain: false)
43
+ logger_method = detect_logger_method
44
+ color_method = detect_color_method(color)
45
+ formatter_method = detect_formatter_method(format, colorize: color.present?, explain: explain)
46
+
47
+ line = pattern * count
48
+ caller_path = clean_caller_path(caller[caller_depth])
49
+ caller_path_line = ["source:".colorize(:light_black).underline, caller_path].join(" ")
50
+ timestamp_line = ["timestamp:".colorize(:light_black).underline, Time.now].join(" ")
51
+
52
+ if block_given?
53
+ result = yield
54
+ top_line =
55
+ if label.present? && label.is_a?(String)
56
+ wrapped_line(label.to_s, pattern: pattern, count: count)
57
+ else
58
+ pattern * count
59
+ end
60
+ result.tap do
61
+ logger_method.call color_method.call "\n\n#{top_line}"
62
+ logger_method.call timestamp_line
63
+ logger_method.call caller_path_line
64
+ logger_method.call ""
65
+ logger_method.call formatter_method.call(result)
66
+ logger_method.call color_method.call "#{line}\n\n"
67
+ end
68
+ else
69
+ tap do
70
+ logger_method.call color_method.call "\n\n#{line}"
71
+ logger_method.call timestamp_line
72
+ logger_method.call caller_path_line
73
+ logger_method.call ""
74
+ logger_method.call formatter_method.call(label)
75
+ logger_method.call color_method.call "#{line}\n\n"
76
+ end
77
+ end
78
+ end
79
+
80
+ private
81
+
82
+ # Remove the Rails.root from the caller path
83
+ # @param [String] caller_path - path of the the file and line number of the caller
84
+ # @return [String]
85
+ def clean_caller_path(caller_path)
86
+ return caller_path unless defined?(Rails)
87
+
88
+ caller_path.gsub(Rails.root.to_s, "")
89
+ end
90
+
91
+ # Detect the colorize method to use
92
+ # @param [Symbol] color
93
+ # @return [Method] the colorize method
94
+ def detect_color_method(color)
95
+ return ->(message) { message } unless color
96
+
97
+ color = color.to_sym
98
+ raise ArgumentError, "Invalid color: #{color}. Must be one of #{COLORS}" unless COLORS.include?(color)
99
+
100
+ ->(message) { message.colorize(color) }
101
+ end
102
+
103
+ # Detect the logger method to use
104
+ # @return [Method] logger method
105
+ def detect_logger_method
106
+ if Whoop.logger.respond_to?(Whoop.level)
107
+ Whoop.logger.method(Whoop.level)
108
+ else
109
+ method(:puts)
110
+ end
111
+ end
112
+
113
+ # Return the format method to use
114
+ # @param [Symbol] format
115
+ # @return [Method] format method
116
+ def detect_formatter_method(format, colorize: false, explain: false)
117
+ case format.to_sym
118
+ when :json
119
+ ->(message) { Whoop::Formatters::JsonFormatter.format(message, colorize: colorize) }
120
+ when :sql
121
+ ->(message) { Whoop::Formatters::SqlFormatter.format(message, colorize: colorize, explain: explain) }
122
+ else
123
+ ->(message) { message }
124
+ end
125
+ end
126
+
127
+ # Return the line with the label centered in it
128
+ # @param [String] label
129
+ # @param [Integer] count
130
+ # @param [String] pattern
131
+ # @return [String]
132
+ def wrapped_line(label, count: COUNT, pattern: PATTERN)
133
+ line_part_length = [((count - label.length) / 2.0).to_i, 5].max
134
+ line_part = pattern * line_part_length
135
+ [line_part, label, line_part].join(" ")
136
+ end
137
+ end
8
138
  end
139
+
140
+ Object.send :include, Whoop::Main
data/sig/whoop.rbs CHANGED
@@ -1,4 +1,121 @@
1
+ # Whoop.setup do |config|
2
+ # config.logger = ActiveSupport::Logger.new("#{Rails.root}/log/debug.log")
3
+ # config.level = :debug
4
+ # end
1
5
  module Whoop
2
- VERSION: String
3
- # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
- end
6
+ VERSION: untyped
7
+
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
13
+
14
+ module Main
15
+ COLORS: untyped
16
+ FORMATS: untyped
17
+ PATTERN: untyped
18
+ COUNT: untyped
19
+
20
+ # sord omit - no YARD return type given, using untyped
21
+ # Log the message to the logger
22
+ #
23
+ # _@param_ `label` — (optional) - the label or object to log
24
+ #
25
+ # _@param_ `pattern` — - the pattern to use for the line (e.g. '-')
26
+ #
27
+ # _@param_ `count` — - the number of times to repeat the pattern per line (e.g. 80)
28
+ #
29
+ # _@param_ `color` — - the color to use for the line (e.g. :red)
30
+ #
31
+ # _@param_ `format` — - the format to use for the message (one of :json, :sql, :plain)
32
+ #
33
+ # _@param_ `caller_depth` — - the depth of the caller to use for the source (default: 0)
34
+ #
35
+ # _@param_ `explain` — - whether to explain the SQL query (default: false)
36
+ def whoop: (
37
+ ?String? label,
38
+ ?pattern: String,
39
+ ?count: Integer,
40
+ ?color: Symbol,
41
+ ?format: Symbol,
42
+ ?caller_depth: Integer,
43
+ ?explain: bool
44
+ ) -> untyped
45
+
46
+ # Remove the Rails.root from the caller path
47
+ #
48
+ # _@param_ `caller_path` — - path of the the file and line number of the caller
49
+ def clean_caller_path: (String caller_path) -> String
50
+
51
+ # Detect the colorize method to use
52
+ #
53
+ # _@param_ `color`
54
+ #
55
+ # _@return_ — the colorize method
56
+ def detect_color_method: (Symbol color) -> Method
57
+
58
+ # Detect the logger method to use
59
+ #
60
+ # _@return_ — logger method
61
+ def detect_logger_method: () -> Method
62
+
63
+ # sord omit - no YARD type given for "colorize:", using untyped
64
+ # sord omit - no YARD type given for "explain:", using untyped
65
+ # Return the format method to use
66
+ #
67
+ # _@param_ `format`
68
+ #
69
+ # _@return_ — format method
70
+ def detect_formatter_method: (Symbol format, ?colorize: untyped, ?explain: untyped) -> Method
71
+
72
+ # Return the line with the label centered in it
73
+ #
74
+ # _@param_ `label`
75
+ #
76
+ # _@param_ `count`
77
+ #
78
+ # _@param_ `pattern`
79
+ def wrapped_line: (String label, ?count: Integer, ?pattern: String) -> String
80
+ end
81
+
82
+ module Formatters
83
+ module SqlFormatter
84
+ # Format the SQL query
85
+ #
86
+ # _@param_ `sql` — The SQL query
87
+ #
88
+ # _@param_ `colorize` — - colorize the SQL query (default: false)
89
+ #
90
+ # _@param_ `explain` — - also run `EXPLAIN` on the query (default: false)
91
+ #
92
+ # _@return_ — The formatted SQL query
93
+ def self.format: (String sql, ?colorize: bool, ?explain: bool) -> String
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
108
+ end
109
+
110
+ module JsonFormatter
111
+ # Format the SQL query
112
+ #
113
+ # _@param_ `message` — The SQL query
114
+ #
115
+ # _@param_ `colorize` — - colorize the SQL query (default: false)
116
+ #
117
+ # _@return_ — The formatted SQL query
118
+ def self.format: (String message, ?colorize: bool) -> String
119
+ end
120
+ end
121
+ end
metadata CHANGED
@@ -1,15 +1,183 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: whoop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Berry
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-09-22 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2022-09-23 00:00:00.000000000 Z
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'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: anbt-sql-formatter
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: colorize
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rouge
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: magic_frozen_string_literal
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry-byebug
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: rake
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: standard
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: bump
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ - !ruby/object:Gem::Dependency
168
+ name: sord
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
13
181
  description: A simple gem to help you whoop your logs into shape.
14
182
  email:
15
183
  - eric@berry.sh
@@ -26,10 +194,12 @@ files:
26
194
  - LICENSE.txt
27
195
  - README.md
28
196
  - Rakefile
197
+ - cc-test-reporter
29
198
  - lib/whoop.rb
199
+ - lib/whoop/formatters/json_formatter.rb
200
+ - lib/whoop/formatters/sql_formatter.rb
30
201
  - lib/whoop/version.rb
31
202
  - sig/whoop.rbs
32
- - whoop.gemspec
33
203
  homepage: https://github.com/coderberry/whoop
34
204
  licenses:
35
205
  - MIT
data/whoop.gemspec DELETED
@@ -1,39 +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
- # Uncomment to register a new dependency of your gem
35
- # spec.add_dependency "example-gem", "~> 1.0"
36
-
37
- # For more information and examples about making a new gem, check out our
38
- # guide at: https://bundler.io/guides/creating_gem.html
39
- end