rails_sql_prettifier 6.0.4 → 6.0.6

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: b61bd785fc014de67c05ebea9dfb6004c19522ecdbaecd223a8dc59cf3c717d6
4
- data.tar.gz: d192a000935de406e55c4c6119bdd4286176b40a2f7473b7443d584c02187767
3
+ metadata.gz: f1b2fae31052f2d4e36efb1c866a1f69e0a6d1ca94757c17bcd4edf82715fdcb
4
+ data.tar.gz: a981254b8b0fe7187c5131a5dedbde563e06b631dbf775f7232c388eb9a92bec
5
5
  SHA512:
6
- metadata.gz: 3d85372a2cae35a3d590f7632c7e579b7b7595a7a680ceaffcfb4170bcce561ad12701669f85f7e3c29e2e52fca99fcc126982ecb8e412d6e20ca7a506c4cdc1
7
- data.tar.gz: f885d1b7fcff14a35098d05c7802040e16233a4c21601c3299d56618219ab9255b3d794148c7a98d9222d786ed8d154bcc735c39f621494092448f5e25ec21c7
6
+ metadata.gz: ba0edebb77ea3050622d298f44b3cfeeb8bb7837214e6fc663e9da407fffc0145c35b77abbb8b46b063da4864726253fad7208a6c5bc29bdfbca8e231583207a
7
+ data.tar.gz: 7c52e3a94ba9540d05b1b472ecdb492315efde99250783e5a17882ee53285217704044e3a1799592f58d0302969e2c5bc5ec1d233419fa8629204052a2cf449c
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ # 6.0.6
2
+ * pg_adapter_with_nicesql setting will not be set to action for protected_env
3
+ * niceql version set to ~> 0.6 (fixed https://github.com/alekseyl/niceql/issues/16 !)
4
+
5
+ #6.0.5
6
+ * fixed issue [#20](https://github.com/alekseyl/niceql/issues/20)
7
+ * adding support for multiple ruby versions testing using docker-compose
8
+
1
9
  # 6.0.4
2
10
  * Now AR is a dependency not a development dependency
3
11
 
data/Dockerfile_30 ADDED
@@ -0,0 +1,20 @@
1
+ FROM ruby:3.0.3-bullseye
2
+
3
+ WORKDIR /app
4
+ RUN apt-get update && apt-get -y install lsb-release
5
+ #
6
+ RUN wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - && \
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
9
+
10
+ RUN sh -c 'echo "local all all trust" > /etc/postgresql/14/main/pg_hba.conf' && \
11
+ service postgresql start && \
12
+ psql -U postgres -c 'CREATE DATABASE "niceql-test"'
13
+
14
+ RUN gem install bundler
15
+
16
+ COPY lib/rails_sql_prettifier/version.rb /app/lib/rails_sql_prettifier/version.rb
17
+ COPY rails_sql_prettifier.gemspec /app/
18
+ COPY Gemfil* /app/
19
+ #
20
+ RUN bundle install
data/README.md CHANGED
@@ -6,7 +6,7 @@ This gem started as a code extraction from niceql version 0.4.x.
6
6
 
7
7
  It has versioning aligned to the ActiveRecord versions, niceql prior to 0.5 version had hardcoded logic branches based on ActiveRecord versioning.
8
8
 
9
- That is hard to maintain and hard to test, and also coupling with AR is breaking the original idea of the niceql to be a dependentless solution, so now the niceql is a completely railsfree gem yeay! ( It still has some some checks related to AR implemetations in the error prettifying methods. It will be completely decoupled in the future )
9
+ That is hard to maintain and hard to test, and also coupling with AR is breaking the original idea of the niceql to be a dependentless solution, so now the niceql is a completely railsfree gem yeay! ( It still has some some checks related to AR implementations in the error prettifying methods. It will be completely decoupled in the future )
10
10
 
11
11
  Any reasonable suggestions are welcome.
12
12
 
@@ -51,12 +51,14 @@ Or install it yourself as:
51
51
 
52
52
  ```ruby
53
53
  Niceql.configure do |c|
54
- # Setting pg_adapter_with_nicesql to true will force formatting SQL queries
54
+ # Setting pg_adapter_with_nicesql to true will APPLY formatting SQL queries
55
55
  # before execution. Formatted SQL will lead to much better SQL-query debugging and much more clearer error messages
56
56
  # if you are using Postgresql as a data source.
57
- # BUT do not use it in production until https://github.com/alekseyl/niceql/issues/16 is resolved
58
57
  #
59
- # You can adjust pg_adapter in production but do it at your own risk!
58
+ # BUT even though https://github.com/alekseyl/niceql/issues/16 is resolved,
59
+ # there could be other potentially uncovered bugs so its better not to
60
+ # adjust pg_adapter in production, currently there is an additional blocker for that module ProtectedEnv
61
+ # its will not allow patching PGAdapter for other than test/development envs
60
62
  #
61
63
  # If you need to debug SQL queries in production use exec_niceql
62
64
  #
@@ -94,8 +96,6 @@ end
94
96
 
95
97
  ## Usage
96
98
 
97
- ### With ActiveRecord
98
-
99
99
  ```ruby
100
100
  # puts colorized and formatted corresponding SQL query
101
101
  Model.scope.niceql
@@ -103,7 +103,7 @@ end
103
103
  # only formatting without colorization, you can run output of to_niceql as a SQL query in connection.execute
104
104
  Model.scope.to_niceql
105
105
 
106
- # prettify PG errors if scope runs with any
106
+ # will run prettified sql and hence will properly prettify PG errors if scope runs with any
107
107
  Model.scope_with_err.exec_niceql
108
108
  ```
109
109
 
@@ -157,7 +157,10 @@ end
157
157
  If your console support more colors or different schemes, or if you prefer different colorization, then you can override ColorizeString methods.
158
158
  Current colors were selected with dark and white console themes in mind, so a niceql colorization works good for dark, and good enough for white.
159
159
 
160
- ##
160
+ ## Testing
161
+ ```bash
162
+ docker-compose up
163
+ ```
161
164
 
162
165
  ## Contributing
163
166
 
data/docker-compose.yml CHANGED
@@ -3,8 +3,17 @@ version: "3.7"
3
3
  services:
4
4
  test:
5
5
  build: .
6
- image: niceql
7
- command: service postgresql start && rake test
6
+ image: rsp_6_0
7
+ command: /bin/bash -c 'service postgresql start && rake test'
8
+ volumes:
9
+ - '.:/app'
10
+
11
+ test_3_0:
12
+ build:
13
+ context: .
14
+ dockerfile: Dockerfile_30
15
+ image: rsp_6_0_3_0
16
+ command: /bin/bash -c 'service postgresql start && rake test'
8
17
  volumes:
9
18
  - '.:/app'
10
19
 
@@ -1,3 +1,3 @@
1
1
  module RailsSQLPrettifier
2
- VERSION = '6.0.4'
2
+ VERSION = '6.0.6'
3
3
  end
@@ -28,11 +28,13 @@ module RailsSQLPrettifier
28
28
  end
29
29
 
30
30
  module AbstractAdapterLogPrettifier
31
- def log( sql, *args, &block )
31
+ private
32
+ def log( sql, *args, **kwargs, &block )
32
33
  # \n need to be placed because AR log will start with action description + time info.
33
34
  # rescue sql - just to be sure Prettifier wouldn't break production
34
35
  formatted_sql = "\n" + Niceql::Prettifier.prettify_sql(sql) rescue sql
35
- super( formatted_sql, *args, &block )
36
+
37
+ super( formatted_sql, *args, **kwargs, &block )
36
38
  end
37
39
  end
38
40
 
@@ -70,8 +72,8 @@ module RailsSQLPrettifier
70
72
  def configure
71
73
  super
72
74
 
73
- if config.pg_adapter_with_nicesql && defined?( ::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter )
74
- ::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.include( PostgresAdapterNiceQL)
75
+ if config.pg_adapter_with_nicesql && defined?(::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter) && !protected_env?
76
+ ::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.include(PostgresAdapterNiceQL)
75
77
  end
76
78
 
77
79
  ::ActiveRecord::ConnectionAdapters::AbstractAdapter.prepend( AbstractAdapterLogPrettifier ) if config.prettify_active_record_log_output
@@ -80,6 +82,13 @@ module RailsSQLPrettifier
80
82
  end
81
83
  end
82
84
 
85
+ module ProtectedEnv
86
+ def protected_env?
87
+ ActiveRecord::Base.connection.migration_context.protected_environment? ||
88
+ defined?(Rails) && !(Rails.env.test? || Rails.env.development?)
89
+ end
90
+ end
91
+
83
92
  [::ActiveRecord::Relation,
84
93
  ::Arel::TreeManager,
85
94
  ::Arel::Nodes::Node].each { |klass| klass.send(:include, ArExtentions) }
@@ -88,4 +97,5 @@ module RailsSQLPrettifier
88
97
 
89
98
  # we need to use a prepend otherwise it's not preceding Niceql.configure in a lookup chain
90
99
  Niceql.singleton_class.prepend( NiceqlExt )
100
+ Niceql.extend(ProtectedEnv)
91
101
  end
@@ -31,17 +31,18 @@ Gem::Specification.new do |spec|
31
31
  spec.require_paths = ["lib"]
32
32
 
33
33
  spec.required_ruby_version = '>= 2.4'
34
- spec.add_dependency "niceql", '~> 0.5'
34
+ spec.add_dependency "niceql", '~> 0.6'
35
35
  spec.add_dependency "activerecord", '>= 6.0', '< 6.1'
36
36
 
37
37
  spec.add_development_dependency "bundler", ">= 1"
38
38
  spec.add_development_dependency "rake", ">= 12.3.3"
39
39
  spec.add_development_dependency "minitest", "~> 5.0"
40
40
 
41
+ spec.add_development_dependency "awesome_print"
41
42
  spec.add_development_dependency "differ", '~> 0.1'
42
43
  spec.add_development_dependency "pry-byebug", '~> 3.9'
43
44
  spec.add_development_dependency 'sqlite3', '~> 1'
44
45
  spec.add_development_dependency 'pg', '~> 1'
45
46
 
46
- spec.add_development_dependency 'stubberry', '~> 0.1'
47
+ spec.add_development_dependency 'stubberry', '~> 0.2'
47
48
  end
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: 6.0.4
4
+ version: 6.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - alekseyl
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-01-09 00:00:00.000000000 Z
11
+ date: 2022-09-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: niceql
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.5'
19
+ version: '0.6'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.5'
26
+ version: '0.6'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activerecord
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -86,6 +86,20 @@ dependencies:
86
86
  - - "~>"
87
87
  - !ruby/object:Gem::Version
88
88
  version: '5.0'
89
+ - !ruby/object:Gem::Dependency
90
+ name: awesome_print
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
89
103
  - !ruby/object:Gem::Dependency
90
104
  name: differ
91
105
  requirement: !ruby/object:Gem::Requirement
@@ -148,14 +162,14 @@ dependencies:
148
162
  requirements:
149
163
  - - "~>"
150
164
  - !ruby/object:Gem::Version
151
- version: '0.1'
165
+ version: '0.2'
152
166
  type: :development
153
167
  prerelease: false
154
168
  version_requirements: !ruby/object:Gem::Requirement
155
169
  requirements:
156
170
  - - "~>"
157
171
  - !ruby/object:Gem::Version
158
- version: '0.1'
172
+ version: '0.2'
159
173
  description: 'This is an ActiveRecord integration for the SQL prettifier gem niceql. '
160
174
  email:
161
175
  - leshchuk@gmail.com
@@ -169,6 +183,7 @@ files:
169
183
  - ".travis.yml"
170
184
  - CHANGELOG.md
171
185
  - Dockerfile
186
+ - Dockerfile_30
172
187
  - Gemfile
173
188
  - LICENSE.txt
174
189
  - README.md