rails_sql_prettifier 7.0.4 → 7.0.5

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: fdf919f40234cb53ea8a819066c0f83b289a20d25143f130aef38e9145d8c6bb
4
- data.tar.gz: 7b137d512642549c1824b50acaaaf4ad123593814316833ac880a49e3cddb195
3
+ metadata.gz: 178b6c12be831f4a33836aea1ce14e8f6490420f687de6cba3545b8363a71bb6
4
+ data.tar.gz: fc2c6e85fc32dfa3bcc941acf31c229c401cf35458e285f2ef161ee76b22f79b
5
5
  SHA512:
6
- metadata.gz: a1cecf0951a654443dd085c2abf96829af343ea590e9776319cfd9261ad03d5bcd6eb45a65f9c50699a025787ed8c3ca38c574bfd2cee94785f6cad3c252f959
7
- data.tar.gz: 2909521fbfc5f49cfe57aae5ffe68a778ebdcaf4a55f725486ead326a2abe2634431ceba0ba736d98bc9ff1340e3b0e647f1b724cc73d9f9bfb3bab1a4d97f0f
6
+ metadata.gz: c5be4b4ecc5dcc39e495313cd859b41ee30ef21f2cc99508ec5c339b35ea2886afff4f7e0404d9a1b137fef41df1b7faf82f3d23bbe98c2e6bdb282512340a27
7
+ data.tar.gz: 558975a592a45895d2f64d6867a80c04658109dff8d32480f8502ff97a7b46e78fd0d3d598bde331f9385ddc2bd8161a0bef574c3374719c6a2a8cfed4a64bc7
@@ -0,0 +1,6 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: "github-actions"
4
+ directory: "/"
5
+ schedule:
6
+ interval: "weekly"
@@ -0,0 +1,23 @@
1
+ name: CI
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ test:
7
+
8
+ runs-on: ubuntu-latest
9
+
10
+ strategy:
11
+ fail-fast: false
12
+ matrix:
13
+ ruby: ["2.7", "3.0", "3.1", "3.2", "3.3"]
14
+
15
+ steps:
16
+ - uses: actions/checkout@v3
17
+ - name: Set up Ruby
18
+ uses: ruby/setup-ruby@v1
19
+ with:
20
+ bundler-cache: true # 'bundle install' and cache gems
21
+ ruby-version: ${{ matrix.ruby }}
22
+ - name: Run tests
23
+ run: service postgresql start && bundle exec rake test
@@ -0,0 +1,17 @@
1
+ name: RuboCop
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+
9
+ steps:
10
+ - uses: actions/checkout@v3
11
+ - name: Set up Ruby
12
+ uses: ruby/setup-ruby@v1
13
+ with:
14
+ ruby-version: 2.7
15
+ bundler-cache: true # 'bundle install' and cache
16
+ - name: Run RuboCop
17
+ run: bundle exec rubocop --parallel
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ # 7.0.5
2
+ * Fixed tests
3
+ * Restructured code properly
4
+ * Fixed issue with exec_niceql over relation with error, now error will be prettified properly
5
+
1
6
  # 7.0.4
2
7
  * pg_adapter_with_nicesql setting will not be set to action for protected_env
3
8
  * niceql version set to ~> 0.6 (fixed https://github.com/alekseyl/niceql/issues/16 !)
data/Dockerfile CHANGED
@@ -5,13 +5,13 @@ RUN apt-get update && apt-get -y install lsb-release
5
5
  #
6
6
  RUN wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - && \
7
7
  sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' && \
8
- apt-get update && apt-get -y install postgresql postgresql-client-12
8
+ apt-get update && apt-get -y install postgresql postgresql-client-14
9
9
 
10
- RUN sh -c 'echo "local all all trust" > /etc/postgresql/14/main/pg_hba.conf' && \
10
+ RUN sh -c 'echo "local all all trust" > /etc/postgresql/$(ls /etc/postgresql)/main/pg_hba.conf' && \
11
11
  service postgresql start && \
12
12
  psql -U postgres -c 'CREATE DATABASE "niceql-test"'
13
13
 
14
- RUN gem install bundler
14
+ RUN gem install bundler -v 2.4.22
15
15
 
16
16
  COPY lib/rails_sql_prettifier/version.rb /app/lib/rails_sql_prettifier/version.rb
17
17
  COPY rails_sql_prettifier.gemspec /app/
data/Dockerfile_30 CHANGED
@@ -5,13 +5,13 @@ RUN apt-get update && apt-get -y install lsb-release
5
5
  #
6
6
  RUN wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - && \
7
7
  sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' && \
8
- apt-get update && apt-get -y install postgresql postgresql-client-12
8
+ apt-get update && apt-get -y install postgresql postgresql-client-14
9
9
 
10
- RUN sh -c 'echo "local all all trust" > /etc/postgresql/14/main/pg_hba.conf' && \
10
+ RUN sh -c 'echo "local all all trust" > /etc/postgresql/$(ls /etc/postgresql)/main/pg_hba.conf' && \
11
11
  service postgresql start && \
12
12
  psql -U postgres -c 'CREATE DATABASE "niceql-test"'
13
13
 
14
- RUN gem install bundler
14
+ RUN gem install bundler -v 2.4.22
15
15
 
16
16
  COPY lib/rails_sql_prettifier/version.rb /app/lib/rails_sql_prettifier/version.rb
17
17
  COPY rails_sql_prettifier.gemspec /app/
@@ -1,5 +1,5 @@
1
1
  Niceql.configure do |c|
2
- # You can adjust pg_adapter in prooduction at your own risk!
2
+ # You can adjust pg_adapter in production at your own risk!
3
3
  # If you need it in production use exec_niceql
4
4
  # default: false
5
5
  # c.pg_adapter_with_nicesql = Rails.env.development?
@@ -8,4 +8,4 @@ Niceql.configure do |c|
8
8
  # c.indentation_base = 2
9
9
  # c.open_bracket_is_newliner = false
10
10
  # c.prettify_active_record_log_output = false
11
- end
11
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsSQLPrettifier
4
+ module AbstractAdapterLogPrettifier
5
+ private
6
+ def log( sql, *args, **kwargs, &block )
7
+ # \n need to be placed because AR log will start with action description + time info.
8
+ # rescue sql - just to be sure Prettifier wouldn't break production
9
+ formatted_sql = "\n" + Niceql::Prettifier.prettify_sql(sql) rescue sql
10
+
11
+ super( formatted_sql, *args, **kwargs, &block )
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsSQLPrettifier
4
+
5
+ module ArExtentions
6
+ def exec_niceql(reraise = false)
7
+ connection.execute( to_niceql )
8
+ rescue => e
9
+ puts Niceql::Prettifier.prettify_pg_err( e.message, to_niceql )
10
+ raise if reraise
11
+ end
12
+
13
+ def to_niceql
14
+ Niceql::Prettifier.prettify_sql(to_sql, false)
15
+ end
16
+
17
+ def niceql( colorize = true )
18
+ puts Niceql::Prettifier.prettify_sql( to_sql, colorize )
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsSQLPrettifier
4
+ module NiceQLConfigExt
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ attr_accessor :pg_adapter_with_nicesql,
9
+ :prettify_active_record_log_output,
10
+ :prettify_pg_errors
11
+
12
+ # we need to use a prepend otherwise it's not preceding Niceql.configure in a lookup chain
13
+ Niceql.singleton_class.prepend(Configure)
14
+ end
15
+
16
+ def ar_using_pg_adapter?
17
+ ActiveRecord::Base.connection_db_config.adapter == 'postgresql'
18
+ end
19
+
20
+ def initialize
21
+ super
22
+ self.pg_adapter_with_nicesql = false
23
+ self.prettify_active_record_log_output = false
24
+ self.prettify_pg_errors = ar_using_pg_adapter?
25
+ end
26
+
27
+ module Configure
28
+ def configure
29
+ super
30
+
31
+ if config.pg_adapter_with_nicesql &&
32
+ defined?(::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter) && !protected_env?
33
+
34
+ ::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.include(PostgresAdapterNiceQL)
35
+ end
36
+
37
+ ::ActiveRecord::ConnectionAdapters::AbstractAdapter.prepend(AbstractAdapterLogPrettifier) if config.prettify_active_record_log_output
38
+
39
+ ::ActiveRecord::StatementInvalid.include(NiceqlError) if config.prettify_pg_errors && config.ar_using_pg_adapter?
40
+ end
41
+ end
42
+ end
43
+
44
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+ module RailsSQLPrettifier
3
+ module NiceqlError
4
+ def to_s
5
+ # older rails version do not provide sql as a standalone query, instead they
6
+ # deliver joined message, and try(:sql) will set prettify_err with nil in that case
7
+ Niceql.config.prettify_pg_errors ? Niceql::Prettifier.prettify_err(super, try(:sql) ) : super
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsSQLPrettifier
4
+ module PostgresAdapterNiceQL
5
+ def exec_query(sql, *args, **kwargs, &block)
6
+ # replacing sql with prettified sql, that's all
7
+ super( Niceql::Prettifier.prettify_sql(sql, false), *args, **kwargs, &block )
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsSQLPrettifier
4
+
5
+ module ProtectedEnv
6
+ def protected_env?
7
+ ActiveRecord::Base.connection.migration_context.protected_environment? ||
8
+ defined?(Rails) && !(Rails.env.test? || Rails.env.development?)
9
+ end
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module RailsSQLPrettifier
2
- VERSION = '7.0.4'
2
+ VERSION = '7.0.5'
3
3
  end
@@ -1,99 +1,19 @@
1
1
  require "rails_sql_prettifier/version"
2
+ require "rails_sql_prettifier/abstract_adapter_log_prettifier"
3
+ require "rails_sql_prettifier/ar_extensions"
4
+ require "rails_sql_prettifier/niceql_error"
5
+ require "rails_sql_prettifier/nice_ql_config_ext"
6
+ require "rails_sql_prettifier/postgres_adapter_nice_ql"
7
+ require "rails_sql_prettifier/protected_env"
8
+
2
9
  require 'active_record'
3
10
  require "niceql"
4
11
 
5
12
  module RailsSQLPrettifier
13
+ ::ActiveRecord::Relation.include ArExtentions
14
+ ::Arel::TreeManager.include ArExtentions
15
+ ::Arel::Nodes::Node.include ArExtentions
6
16
 
7
- module ArExtentions
8
- def exec_niceql
9
- connection.execute( to_niceql )
10
- end
11
-
12
- def to_niceql
13
- Niceql::Prettifier.prettify_sql(to_sql, false)
14
- end
15
-
16
- def niceql( colorize = true )
17
- puts Niceql::Prettifier.prettify_sql( to_sql, colorize )
18
- end
19
-
20
- end
21
-
22
- module PostgresAdapterNiceQL
23
- def exec_query(sql, name = "SQL", binds = [], prepare: false)
24
- # replacing sql with prettified sql, thats all
25
- super( Niceql::Prettifier.prettify_sql(sql, false), name, binds, prepare: prepare )
26
- end
27
- end
28
-
29
- module AbstractAdapterLogPrettifier
30
- private
31
- def log( sql, *args, **kwargs, &block )
32
- # \n need to be placed because AR log will start with action description + time info.
33
- # rescue sql - just to be sure Prettifier wouldn't break production
34
- formatted_sql = "\n" + Niceql::Prettifier.prettify_sql(sql) rescue sql
35
-
36
- super( formatted_sql, *args, **kwargs, &block )
37
- end
38
- end
39
-
40
- module ErrorExt
41
- def to_s
42
- # older rails version do not provide sql as a standalone query, instead they
43
- # deliver joined message
44
- Niceql.config.prettify_pg_errors ? Niceql::Prettifier.prettify_err(super, try(:sql) ) : super
45
- end
46
- end
47
-
48
- module NiceQLConfigExt
49
- extend ActiveSupport::Concern
50
-
51
- included do
52
- attr_accessor :pg_adapter_with_nicesql,
53
- :prettify_active_record_log_output,
54
- :prettify_pg_errors
55
- end
56
-
57
- def ar_using_pg_adapter?
58
- ActiveRecord::Base.connection_db_config.adapter == 'postgresql'
59
- end
60
-
61
- def initialize
62
- super
63
- self.pg_adapter_with_nicesql = false
64
- self.prettify_active_record_log_output = false
65
- self.prettify_pg_errors = ar_using_pg_adapter?
66
- end
67
- end
68
-
69
- module NiceqlExt
70
- def configure
71
- super
72
-
73
- if config.pg_adapter_with_nicesql && defined?(::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter) && !protected_env?
74
- ::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.include(PostgresAdapterNiceQL)
75
- end
76
-
77
- ::ActiveRecord::ConnectionAdapters::AbstractAdapter.prepend( AbstractAdapterLogPrettifier ) if config.prettify_active_record_log_output
78
-
79
- ::ActiveRecord::StatementInvalid.include( RailsSQLPrettifier::ErrorExt ) if config.prettify_pg_errors && config.ar_using_pg_adapter?
80
- end
81
- end
82
-
83
- module ProtectedEnv
84
- def protected_env?
85
- ActiveRecord::Base.connection.migration_context.protected_environment? ||
86
- defined?(Rails) && !(Rails.env.test? || Rails.env.development?)
87
- end
88
- end
89
-
90
- [::ActiveRecord::Relation,
91
- ::Arel::TreeManager,
92
- ::Arel::Nodes::Node].each { |klass| klass.send(:include, ArExtentions) }
93
-
94
- Niceql::NiceQLConfig.include( NiceQLConfigExt )
95
-
96
- # we need to use a prepend otherwise it's not preceding Niceql.configure in a lookup chain
97
- Niceql.singleton_class.prepend( NiceqlExt )
17
+ Niceql::NiceQLConfig.include(NiceQLConfigExt)
98
18
  Niceql.extend(ProtectedEnv)
99
- end
19
+ end
@@ -30,9 +30,10 @@ Gem::Specification.new do |spec|
30
30
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
31
  spec.require_paths = ["lib"]
32
32
 
33
- spec.required_ruby_version = '>= 2.4'
33
+ # for rails 7 you cannot use ruby below 2.7
34
+ spec.required_ruby_version = '>= 2.7'
34
35
  spec.add_dependency "niceql", '~> 0.6'
35
- spec.add_dependency "activerecord", '>= 7'
36
+ spec.add_dependency "activerecord", '>= 7', '< 8'
36
37
 
37
38
  spec.add_development_dependency "bundler", ">= 1"
38
39
  spec.add_development_dependency "rake", ">= 12.3.3"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_sql_prettifier
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.0.4
4
+ version: 7.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - alekseyl
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-09-17 00:00:00.000000000 Z
11
+ date: 2025-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: niceql
@@ -31,6 +31,9 @@ dependencies:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '7'
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: '8'
34
37
  type: :runtime
35
38
  prerelease: false
36
39
  version_requirements: !ruby/object:Gem::Requirement
@@ -38,6 +41,9 @@ dependencies:
38
41
  - - ">="
39
42
  - !ruby/object:Gem::Version
40
43
  version: '7'
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: '8'
41
47
  - !ruby/object:Gem::Dependency
42
48
  name: bundler
43
49
  requirement: !ruby/object:Gem::Requirement
@@ -171,10 +177,12 @@ executables: []
171
177
  extensions: []
172
178
  extra_rdoc_files: []
173
179
  files:
180
+ - ".github/dependabot.yml"
181
+ - ".github/workflows/ci.yml"
182
+ - ".github/workflows/rubocop.yml"
174
183
  - ".gitignore"
175
184
  - ".ruby-gemset"
176
185
  - ".ruby-version"
177
- - ".travis.yml"
178
186
  - CHANGELOG.md
179
187
  - Dockerfile
180
188
  - Dockerfile_30
@@ -193,6 +201,12 @@ files:
193
201
  - lib/generators/niceql/install_generator.rb
194
202
  - lib/generators/templates/niceql_initializer.rb
195
203
  - lib/rails_sql_prettifier.rb
204
+ - lib/rails_sql_prettifier/abstract_adapter_log_prettifier.rb
205
+ - lib/rails_sql_prettifier/ar_extensions.rb
206
+ - lib/rails_sql_prettifier/nice_ql_config_ext.rb
207
+ - lib/rails_sql_prettifier/niceql_error.rb
208
+ - lib/rails_sql_prettifier/postgres_adapter_nice_ql.rb
209
+ - lib/rails_sql_prettifier/protected_env.rb
196
210
  - lib/rails_sql_prettifier/version.rb
197
211
  - rails_sql_prettifier.gemspec
198
212
  - to_niceql.png
@@ -209,14 +223,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
209
223
  requirements:
210
224
  - - ">="
211
225
  - !ruby/object:Gem::Version
212
- version: '2.4'
226
+ version: '2.7'
213
227
  required_rubygems_version: !ruby/object:Gem::Requirement
214
228
  requirements:
215
229
  - - ">="
216
230
  - !ruby/object:Gem::Version
217
231
  version: '0'
218
232
  requirements: []
219
- rubygems_version: 3.1.4
233
+ rubygems_version: 3.3.26
220
234
  signing_key:
221
235
  specification_version: 4
222
236
  summary: This is an ActiveRecord integration for the SQL prettifier gem niceql.
data/.travis.yml DELETED
@@ -1,7 +0,0 @@
1
- sudo: false
2
- language: ruby
3
- rvm:
4
- - 2.4
5
- - 2.5
6
- - 2.3
7
- - 2.6