pp_sql 1.1.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/MIT-LICENSE +1 -1
- data/README.md +16 -17
- data/lib/pp_sql/version.rb +1 -1
- data/lib/pp_sql.rb +16 -43
- metadata +15 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 440b603309167e4817b3d9d2ff322ba2e366b3e769856e79473e549f5861ff08
|
4
|
+
data.tar.gz: 969048128509ccd2415d172ce25565cc81bd21b5078acd5f4fb0a0b87cb4eb90
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a7c0eb0ab3745214a588687ac0e16b2205d7cdc44ce8d887b45a1c95e4e71367e6ab99d2e943932046041bf7d4866bb8c147c08cd695cf979c971c5f35977943
|
7
|
+
data.tar.gz: 5c3c1c3f38d42ddcd4c3ec64e68910b9a2d82198e5a433cbc9d37e8a4e4f154b43ff19ffc6c603e5bc131bad7bf6761085f8b3aba5d891553ed7f8a8f928e8d8
|
data/MIT-LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# PpSql
|
2
2
|
|
3
3
|
[![Version ][rubygems_badge]][rubygems]
|
4
|
-
[![Build Status ][travisci_badge]][travisci]
|
5
4
|
[![Codacy Badge ][codacy_badge]][codacy]
|
6
5
|
[![Reviewed by Hound ][hound_badge]][hound]
|
7
6
|
|
@@ -18,11 +17,11 @@ Or in console
|
|
18
17
|
|
19
18
|
## Require
|
20
19
|
|
21
|
-
Ruby
|
20
|
+
Ruby 3.1+
|
22
21
|
|
23
22
|
## Rails
|
24
23
|
|
25
|
-
Rails
|
24
|
+
Rails 7.0+ (optional), will be injected automatically
|
26
25
|
|
27
26
|
## Legacy
|
28
27
|
|
@@ -34,13 +33,7 @@ You can use version `~> 0.2` of this gem with Ruby 2.2, 2.3 and/or Rails 4.0, 4.
|
|
34
33
|
Post.first.to_sql
|
35
34
|
```
|
36
35
|
|
37
|
-
for easy and clean usage with custom string you can use
|
38
|
-
|
39
|
-
```
|
40
|
-
using PpSql::ToSqlBeautifyRefinement
|
41
|
-
```
|
42
|
-
|
43
|
-
Or if you need to use it wider
|
36
|
+
for easy and clean usage with custom string you can use:
|
44
37
|
|
45
38
|
```
|
46
39
|
class MyAwesomeDecoratedString < String
|
@@ -51,13 +44,15 @@ end
|
|
51
44
|
## Installation
|
52
45
|
|
53
46
|
add in Gemfile
|
47
|
+
|
54
48
|
```
|
55
49
|
gem 'pp_sql', group: :development
|
56
50
|
```
|
57
51
|
|
58
52
|
And then execute:
|
53
|
+
|
59
54
|
```bash
|
60
|
-
|
55
|
+
bundle
|
61
56
|
```
|
62
57
|
|
63
58
|
## With other formatters
|
@@ -73,7 +68,7 @@ If you do not want to rewrite default `#to_sql` method you may specify
|
|
73
68
|
You can also disable log formatting by specifying `PpSql.add_rails_logger_formatting=false`
|
74
69
|
in initializers.
|
75
70
|
|
76
|
-
|
71
|
+
### Add to Application record
|
77
72
|
|
78
73
|
I found usefull this trick:
|
79
74
|
|
@@ -89,16 +84,20 @@ end
|
|
89
84
|
|
90
85
|
[![jetbrains][jetbrains-img-link]][jetbrains-link]
|
91
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
|
+
|
92
92
|
## License
|
93
|
+
|
93
94
|
The gem is available as open source under the terms of the
|
94
95
|
[MIT License][mit-licence-link].
|
95
96
|
|
96
97
|
[rubygems_badge]: http://img.shields.io/gem/v/pp_sql.svg
|
97
98
|
[rubygems]: https://rubygems.org/gems/pp_sql
|
98
|
-
[
|
99
|
-
[
|
100
|
-
[codacy_badge]: https://api.codacy.com/project/badge/Grade/7c866da60b1b4dd78eacc379cc0e7f3b
|
101
|
-
[codacy]: https://www.codacy.com/app/kvokka/pp_sql?utm_source=github.com&utm_medium=referral&utm_content=kvokka/pp_sql&utm_campaign=Badge_Grade
|
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&utm_medium=referral&utm_content=kvokka/pp_sql&utm_campaign=Badge_Grade
|
102
101
|
[hound_badge]: https://img.shields.io/badge/Reviewed_by-Hound-8E64B0.svg
|
103
102
|
[hound]: https://houndci.com
|
104
103
|
|
@@ -108,4 +107,4 @@ The gem is available as open source under the terms of the
|
|
108
107
|
[jetbrains-img-link]: https://raw.githubusercontent.com/kvokka/pp_sql/master/img/jetbrains-variant-3.svg?sanitize=true
|
109
108
|
|
110
109
|
[log-img]: https://raw.githubusercontent.com/kvokka/pp_sql/master/img/log.png
|
111
|
-
[console-img]: https://raw.githubusercontent.com/kvokka/pp_sql/master/img/console.png
|
110
|
+
[console-img]: https://raw.githubusercontent.com/kvokka/pp_sql/master/img/console.png
|
data/lib/pp_sql/version.rb
CHANGED
data/lib/pp_sql.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
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
|
7
|
-
attr_accessor :rewrite_to_sql_method
|
8
|
-
attr_accessor :add_rails_logger_formatting
|
9
|
+
attr_accessor :rewrite_to_sql_method, :add_rails_logger_formatting
|
9
10
|
end
|
10
11
|
self.rewrite_to_sql_method = true
|
11
12
|
self.add_rails_logger_formatting = true
|
@@ -20,54 +21,27 @@ module PpSql
|
|
20
21
|
rule = AnbtSql::Rule.new
|
21
22
|
rule.keyword = AnbtSql::Rule::KEYWORD_UPPER_CASE
|
22
23
|
%w[count sum substr date].each { |func_name| rule.function_names << func_name.upcase }
|
23
|
-
rule.indent_string =
|
24
|
+
rule.indent_string = WHITE_SPACE
|
24
25
|
@_sql_formatter = AnbtSql::Formatter.new(rule)
|
25
26
|
end
|
26
27
|
end
|
27
28
|
|
28
29
|
module ToSqlBeautify
|
29
30
|
def to_sql
|
30
|
-
|
31
|
-
|
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)
|
31
|
+
if ::PpSql.rewrite_to_sql_method
|
32
|
+
extend Formatter
|
33
|
+
_sql_formatter.format(defined?(super) ? super.dup : dup)
|
56
34
|
else
|
57
|
-
|
35
|
+
defined?(super) ? super : self
|
58
36
|
end
|
59
37
|
end
|
60
38
|
|
61
|
-
def
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
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
|
39
|
+
def pp_sql
|
40
|
+
if ::PpSql.rewrite_to_sql_method
|
41
|
+
puts to_sql
|
42
|
+
else
|
43
|
+
extend Formatter
|
44
|
+
puts _sql_formatter.format(to_sql.dup)
|
71
45
|
end
|
72
46
|
end
|
73
47
|
end
|
@@ -88,9 +62,8 @@ module PpSql
|
|
88
62
|
class Railtie < Rails::Railtie
|
89
63
|
initializer 'pp_sql.override_to_sql' do
|
90
64
|
ActiveSupport.on_load(:active_record) do
|
91
|
-
ActiveRecord::Relation.
|
92
|
-
ActiveRecord::LogSubscriber.
|
93
|
-
ActiveRecord::LogSubscriber.send(:include, Rails5PpSqlExtraction) if Rails::VERSION::MAJOR <= 4
|
65
|
+
ActiveRecord::Relation.prepend ToSqlBeautify
|
66
|
+
ActiveRecord::LogSubscriber.prepend LogSubscriberPrettyPrint
|
94
67
|
end
|
95
68
|
end
|
96
69
|
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:
|
4
|
+
version: 2.1.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:
|
11
|
+
date: 2024-12-22 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
|
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
|
40
|
+
version: 0.1.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: minitest
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -86,28 +86,28 @@ dependencies:
|
|
86
86
|
requirements:
|
87
87
|
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
89
|
+
version: '7.0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
96
|
+
version: '7.0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: sqlite3
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- - "
|
101
|
+
- - ">="
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: 1.
|
103
|
+
version: '1.4'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- - "
|
108
|
+
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: 1.
|
110
|
+
version: '1.4'
|
111
111
|
description: Helps to save your eyes, when reading hardcore SQL requests in console
|
112
112
|
email:
|
113
113
|
- kvokka@yahoo.com
|
@@ -124,7 +124,7 @@ homepage: https://github.com/kvokka/pp_sql
|
|
124
124
|
licenses:
|
125
125
|
- MIT
|
126
126
|
metadata: {}
|
127
|
-
post_install_message:
|
127
|
+
post_install_message:
|
128
128
|
rdoc_options: []
|
129
129
|
require_paths:
|
130
130
|
- lib
|
@@ -132,15 +132,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
132
132
|
requirements:
|
133
133
|
- - ">="
|
134
134
|
- !ruby/object:Gem::Version
|
135
|
-
version:
|
135
|
+
version: 3.1.0
|
136
136
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
137
|
requirements:
|
138
138
|
- - ">="
|
139
139
|
- !ruby/object:Gem::Version
|
140
140
|
version: '0'
|
141
141
|
requirements: []
|
142
|
-
rubygems_version: 3.
|
143
|
-
signing_key:
|
142
|
+
rubygems_version: 3.4.1
|
143
|
+
signing_key:
|
144
144
|
specification_version: 4
|
145
145
|
summary: Beautify SQL output of ActiveRecord#to_sql
|
146
146
|
test_files: []
|