pp_sql 1.0.0 → 2.0.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1a49d6ae724e77c43994b020855277ac0b8f092dc33655a860ac6a03eaf0c80d
4
- data.tar.gz: ccc533f5a973a3d280eb9d767d034b637adf2ea8c1bafc4299709382b70e9146
3
+ metadata.gz: 7a559008902010eaf5b28733b39837e48d5a79c74caa4d2075161a9d83900e0c
4
+ data.tar.gz: 3059d4e7c694d2a80838142668c7da7277ca083548ddeb3a9ebd1987addaee4b
5
5
  SHA512:
6
- metadata.gz: 017fa759809e722c95298ffcadf962763dc5412f89da88505e84b3478b06b14e426339b7789dace42766ac3d6f14d047cb5bc656482ffdb6dd382dfb1eb13bed
7
- data.tar.gz: 66f58caeabe0b1a5a49f6320485e29f8030fa40d2d404a9a4b8feb409eaea7aaea737bba83be53fe32db498aa38ddc7403416e4b6532264023047eb05bdd7d15
6
+ metadata.gz: 6c26a69252eacb551d9585078158129a98b3350835a9a5b60c5100a4998e668dbd5de731fc65fd300f1fea88a1e96fccd8f663b4e24b4154b28e2ae1328aab7d
7
+ data.tar.gz: 764fb72223cb662688b06646a6181fe79a43f6f1513d4f9140ce5bb17c00d88fc8c7be971859c0095c18135ce1a498b10062bc55dea9b06da1d18fe647f1e24c
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2017 Kvokka
1
+ Copyright 2023 Kvokka
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,40 +1,39 @@
1
1
  # PpSql
2
- [![Build Status](https://travis-ci.org/kvokka/pp_sql.svg?branch=master)](https://travis-ci.org/kvokka/pp_sql)
3
- [![Codacy Badge](https://api.codacy.com/project/badge/Grade/7c866da60b1b4dd78eacc379cc0e7f3b)](https://www.codacy.com/app/kvokka/pp_sql?utm_source=github.com&utm_medium=referral&utm_content=kvokka/pp_sql&utm_campaign=Badge_Grade)
4
- [![Reviewed by Hound](https://img.shields.io/badge/Reviewed_by-Hound-8E64B0.svg)](https://houndci.com)
2
+
3
+ [![Version ][rubygems_badge]][rubygems]
4
+ [![Codacy Badge ][codacy_badge]][codacy]
5
+ [![Reviewed by Hound ][hound_badge]][hound]
5
6
 
6
7
  Replace standard `ActiveRecord#to_sql` method with
7
- [`anbt-sql-formatter`](https://github.com/sonota88/anbt-sql-formatter)
8
+ [`anbt-sql-formatter`][anbt-sql-formatter-link]
8
9
  gem for pretty SQL code output in console. Rails log will be formatted also.
9
10
  Example output:
10
11
 
11
- ![log](https://raw.githubusercontent.com/kvokka/pp_sql/master/screenshots/log.png)
12
+ ![log][log-img]
12
13
 
13
14
  Or in console
14
15
 
15
- ![console](https://raw.githubusercontent.com/kvokka/pp_sql/master/screenshots/console.png)
16
+ ![console][console-img]
16
17
 
17
18
  ## Require
18
19
 
19
- Ruby 2.2+
20
+ Ruby 2.4+
20
21
 
21
22
  ## Rails
22
23
 
23
- Rails 4.0+ (optional), will be injected automatically
24
+ Rails 5.0+ (optional), will be injected automatically
24
25
 
25
- ## Usage
26
+ ## Legacy
26
27
 
27
- ```
28
- Post.first.to_sql
29
- ```
28
+ You can use version `~> 0.2` of this gem with Ruby 2.2, 2.3 and/or Rails 4.0, 4.1
30
29
 
31
- for easy and clean usage with custom string you can use build-in refinement:
30
+ ## Usage
32
31
 
33
32
  ```
34
- using PpSql::ToSqlBeautifyRefinement
33
+ Post.first.to_sql
35
34
  ```
36
35
 
37
- Or if you need to use it wider
36
+ for easy and clean usage with custom string you can use:
38
37
 
39
38
  ```
40
39
  class MyAwesomeDecoratedString < String
@@ -45,13 +44,15 @@ end
45
44
  ## Installation
46
45
 
47
46
  add in Gemfile
47
+
48
48
  ```
49
49
  gem 'pp_sql', group: :development
50
50
  ```
51
51
 
52
52
  And then execute:
53
+
53
54
  ```bash
54
- $ bundle
55
+ bundle
55
56
  ```
56
57
 
57
58
  ## With other formatters
@@ -67,7 +68,7 @@ If you do not want to rewrite default `#to_sql` method you may specify
67
68
  You can also disable log formatting by specifying `PpSql.add_rails_logger_formatting=false`
68
69
  in initializers.
69
70
 
70
- ### Add to Application record
71
+ ### Add to Application record
71
72
 
72
73
  I found usefull this trick:
73
74
 
@@ -79,6 +80,31 @@ I found usefull this trick:
79
80
  end
80
81
  ```
81
82
 
83
+ ### Supported by
84
+
85
+ [![jetbrains][jetbrains-img-link]][jetbrains-link]
86
+
87
+ ## Contributing
88
+
89
+ Running the tests requires sqlite. To run the tests for different combinations of dependency
90
+ versions, run `bundle exec appraisal install` followed by `bundle exec appraisal rake`.
91
+
82
92
  ## License
93
+
83
94
  The gem is available as open source under the terms of the
84
- [MIT License](http://opensource.org/licenses/MIT).
95
+ [MIT License][mit-licence-link].
96
+
97
+ [rubygems_badge]: http://img.shields.io/gem/v/pp_sql.svg
98
+ [rubygems]: https://rubygems.org/gems/pp_sql
99
+ [codacy_badge]: https://app.codacy.com/project/badge/Grade/0394889311ea49529ddea12baac9b699
100
+ [codacy]: https://www.codacy.com/gh/kvokka/pp_sql/dashboard?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=kvokka/pp_sql&amp;utm_campaign=Badge_Grade
101
+ [hound_badge]: https://img.shields.io/badge/Reviewed_by-Hound-8E64B0.svg
102
+ [hound]: https://houndci.com
103
+
104
+ [anbt-sql-formatter-link]: https://github.com/sonota88/anbt-sql-formatter
105
+ [mit-licence-link]: http://opensource.org/licenses/MIT
106
+ [jetbrains-link]: https://www.jetbrains.com/?from=pp_sql
107
+ [jetbrains-img-link]: https://raw.githubusercontent.com/kvokka/pp_sql/master/img/jetbrains-variant-3.svg?sanitize=true
108
+
109
+ [log-img]: https://raw.githubusercontent.com/kvokka/pp_sql/master/img/log.png
110
+ [console-img]: https://raw.githubusercontent.com/kvokka/pp_sql/master/img/console.png
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PpSql
4
- VERSION = '1.0.0'
4
+ VERSION = '2.0.0'
5
5
  end
data/lib/pp_sql.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PpSql
4
+ WHITE_SPACE = ' '
5
+
4
6
  # if you do not want to rewrite AR native method #to_sql
5
7
  # you may switch this setting to false in initializer
6
8
  class << self
@@ -20,54 +22,27 @@ module PpSql
20
22
  rule = AnbtSql::Rule.new
21
23
  rule.keyword = AnbtSql::Rule::KEYWORD_UPPER_CASE
22
24
  %w[count sum substr date].each { |func_name| rule.function_names << func_name.upcase }
23
- rule.indent_string = ' '
25
+ rule.indent_string = WHITE_SPACE
24
26
  @_sql_formatter = AnbtSql::Formatter.new(rule)
25
27
  end
26
28
  end
27
29
 
28
30
  module ToSqlBeautify
29
31
  def to_sql
30
- return self unless ::PpSql.rewrite_to_sql_method || defined?(super)
31
- return super unless ::PpSql.rewrite_to_sql_method
32
-
33
- extend Formatter
34
- _sql_formatter.format(defined?(super) ? super.dup : dup)
35
- end
36
-
37
- def pp_sql
38
- puts to_sql
39
- end
40
- end
41
-
42
- module ToSqlBeautifyRefinement
43
- refine String do
44
- include PpSql::ToSqlBeautify
45
- end
46
- end
47
-
48
- module Rails5PpSqlExtraction
49
- # export from Rails 5 with for Rails 4.2+ versions
50
-
51
- private
52
-
53
- def colorize_payload_name(name, payload_name)
54
- if payload_name.blank? || payload_name == 'SQL' # SQL vs Model Load/Exists
55
- color(name, ActiveSupport::LogSubscriber::MAGENTA, true)
32
+ if ::PpSql.rewrite_to_sql_method
33
+ extend Formatter
34
+ _sql_formatter.format(defined?(super) ? super.dup : dup)
56
35
  else
57
- color(name, ActiveSupport::LogSubscriber::CYAN, true)
36
+ defined?(super) ? super : self
58
37
  end
59
38
  end
60
39
 
61
- def sql_color(sql)
62
- case sql
63
- when /\A\s*rollback/mi then ActiveSupport::LogSubscriber::RED
64
- when /select .*for update/mi, /\A\s*lock/mi then ActiveSupport::LogSubscriber::WHITE
65
- when /\A\s*select/i then ActiveSupport::LogSubscriber::BLUE
66
- when /\A\s*insert/i then ActiveSupport::LogSubscriber::GREEN
67
- when /\A\s*update/i then ActiveSupport::LogSubscriber::YELLOW
68
- when /\A\s*delete/i then ActiveSupport::LogSubscriber::RED
69
- when /transaction\s*\Z/i then ActiveSupport::LogSubscriber::CYAN
70
- else ActiveSupport::LogSubscriber::MAGENTA
40
+ def pp_sql
41
+ if ::PpSql.rewrite_to_sql_method
42
+ puts to_sql
43
+ else
44
+ extend Formatter
45
+ puts _sql_formatter.format(to_sql.to_s)
71
46
  end
72
47
  end
73
48
  end
@@ -90,7 +65,6 @@ module PpSql
90
65
  ActiveSupport.on_load(:active_record) do
91
66
  ActiveRecord::Relation.send(:prepend, ToSqlBeautify)
92
67
  ActiveRecord::LogSubscriber.send(:prepend, LogSubscriberPrettyPrint)
93
- ActiveRecord::LogSubscriber.send(:include, Rails5PpSqlExtraction) if Rails::VERSION::MAJOR <= 4
94
68
  end
95
69
  end
96
70
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pp_sql
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kvokka
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-06-22 00:00:00.000000000 Z
11
+ date: 2023-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.0.6
33
+ version: 0.1.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.0.6
40
+ version: 0.1.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: minitest
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -80,20 +80,34 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rails
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '5.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '5.0'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: sqlite3
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
- - - "~>"
101
+ - - ">="
88
102
  - !ruby/object:Gem::Version
89
- version: 1.3.6
103
+ version: '1.4'
90
104
  type: :development
91
105
  prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
94
- - - "~>"
108
+ - - ">="
95
109
  - !ruby/object:Gem::Version
96
- version: 1.3.6
110
+ version: '1.4'
97
111
  description: Helps to save your eyes, when reading hardcore SQL requests in console
98
112
  email:
99
113
  - kvokka@yahoo.com
@@ -110,7 +124,7 @@ homepage: https://github.com/kvokka/pp_sql
110
124
  licenses:
111
125
  - MIT
112
126
  metadata: {}
113
- post_install_message:
127
+ post_install_message:
114
128
  rdoc_options: []
115
129
  require_paths:
116
130
  - lib
@@ -125,8 +139,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
139
  - !ruby/object:Gem::Version
126
140
  version: '0'
127
141
  requirements: []
128
- rubygems_version: 3.0.3
129
- signing_key:
142
+ rubygems_version: 3.1.4
143
+ signing_key:
130
144
  specification_version: 4
131
145
  summary: Beautify SQL output of ActiveRecord#to_sql
132
146
  test_files: []