pp_sql 1.1.0 → 2.0.0

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: d3857bf4ee1bc273f4149f85b7d460b8dde9fc4e48b5754077171729f64a70fa
4
- data.tar.gz: 1473bdfc1a0bd0b381dffb6714047f74c0bc39b32256d7c2abc5ac36710d2319
3
+ metadata.gz: 7a559008902010eaf5b28733b39837e48d5a79c74caa4d2075161a9d83900e0c
4
+ data.tar.gz: 3059d4e7c694d2a80838142668c7da7277ca083548ddeb3a9ebd1987addaee4b
5
5
  SHA512:
6
- metadata.gz: b5ea458f000dfd8a62a99ec3a3e2822ea6195f95ceb536688751c41bfa88dc1f9ab548f044e8d3c253d3d9d23b3e70ffa338d5fcd0ac5278401dd585e8e920c5
7
- data.tar.gz: f1a913c68c4065cb179ea74bec52a4c2cf1413a08045fe1f46958458cc5607abb295780a51cdaa3413e4033645ea733f6d6f55c0d34616b9b7f557fbaa6d3ea7
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,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
 
@@ -22,7 +21,7 @@ Ruby 2.4+
22
21
 
23
22
  ## Rails
24
23
 
25
- Rails 4.2+ (optional), will be injected automatically
24
+ Rails 5.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 build-in refinement:
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
- $ bundle
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
- ### Add to Application record
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
- [travisci_badge]: https://travis-ci.org/kvokka/pp_sql.svg?branch=master
99
- [travisci]: https://travis-ci.org/kvokka/pp_sql
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&amp;utm_medium=referral&amp;utm_content=kvokka/pp_sql&amp;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&amp;utm_medium=referral&amp;utm_content=kvokka/pp_sql&amp;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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PpSql
4
- VERSION = '1.1.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.1.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-09-13 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
@@ -86,28 +86,28 @@ dependencies:
86
86
  requirements:
87
87
  - - ">="
88
88
  - !ruby/object:Gem::Version
89
- version: '4.2'
89
+ version: '5.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: '4.2'
96
+ version: '5.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.3.6
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.3.6
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
@@ -139,8 +139,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
139
  - !ruby/object:Gem::Version
140
140
  version: '0'
141
141
  requirements: []
142
- rubygems_version: 3.0.4
143
- signing_key:
142
+ rubygems_version: 3.1.4
143
+ signing_key:
144
144
  specification_version: 4
145
145
  summary: Beautify SQL output of ActiveRecord#to_sql
146
146
  test_files: []