rails_sql_prettifier 5.0.5 → 6.0.2

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: ba0aedcc17d28557a7bb000e0ed40a926c68d49607336640caa0d1b7fdb8def5
4
- data.tar.gz: b062509b0ad5b03095d5e5ac8ae8555c463c345e67dc115cab59cc3c1bf4ee43
3
+ metadata.gz: dc8698d2cb6da1287057ee6d57f4fa1d494efa19bcc013157012d0a055176243
4
+ data.tar.gz: 6e41b147fd207cc2ad6afcd48508b1ebb0e6cf183d5d3829b61fffff71e1ed30
5
5
  SHA512:
6
- metadata.gz: 48be6e8685ae50b452e3793fa8e05e594debbf08a7b501c57de0a97805104d8afbb8f543366e73e539e28b837c6e86af9a8434d0e7e9b9f249a52853cdc0f092
7
- data.tar.gz: 6e1aa511179a91313381fa05f16ebc71aef8710a32a580b6d472afce4022aecae99627394e23cdfe392603269843e54a78cbdb7f1d37a083dd7e4d3c5f720b2f
6
+ metadata.gz: 4b2da81bae482d9269ae444ceb7c58b73c0d769755b45d2455656169c117bfe22a18ec0288989689479c385afa5c86f00ae826f3c477d5b987e04e3da97acdcf
7
+ data.tar.gz: 6030b09100f99471a4874b4f30ccea42184a76eda6f6a7d8a1cb89233498f2b403766ef14981fdfaef15cca1413cdbeb9e5f17fb31e91e07729d779dd609a470
data/.ruby-gemset CHANGED
@@ -1 +1 @@
1
- rails_sql_prettifier_ar_5
1
+ rails_sql_prettifier_ar_6_0
data/CHANGELOG.md CHANGED
@@ -1,18 +1,6 @@
1
- # 5.0.5
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 !)
1
+ # 6.0.2
4
2
 
5
- #5.0.4
6
- * fixed issue [#20](https://github.com/alekseyl/niceql/issues/20)
7
- * adding support for multiple ruby versions testing using docker-compose
8
-
9
- # 5.0.3
10
- * active record versioning is properly aligned now
11
-
12
- # 5.0.2
13
- * Fixed issue with Niceql.configure not configuring anything + test covered
14
-
15
- # 5.0.0
16
-
17
- * This a active record prior to 6.0 version compatible niceql integration
18
- ( main difference is StatementInvalid initialization, starting version 6 it has named param sql: for original query )
3
+ * This a active record prior to 7.0 version and >= 6.1 compatible niceql integration
4
+ ar < 6.0 breaking change:
5
+ * StatementInvalid initialization has a breaking change: starting version 6 it has named param sql: for original query )
6
+
data/README.md CHANGED
@@ -1,12 +1,7 @@
1
1
  # RailsSQLPrettifier
2
2
 
3
- This is an ActiveRecord integration for a niceql gem ( niceql is a small, nice, simple and zero dependency solution for the SQL prettifying in ruby ).
4
-
5
- This gem started as a code extraction from niceql version 0.4.x.
6
-
7
- It has versioning aligned to the ActiveRecord versions, niceql prior to 0.5 version had hardcoded logic branches based on ActiveRecord versioning.
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 implementations in the error prettifying methods. It will be completely decoupled in the future )
3
+ This is an ActiveRecord integration for a niceql gem.
4
+ Niceql is a small, nice, simple and zero dependency solution for SQL prettifying for Ruby.
10
5
 
11
6
  Any reasonable suggestions are welcome.
12
7
 
@@ -28,13 +23,10 @@ after:
28
23
 
29
24
  ## Installation
30
25
 
31
- rails_sql_prettifier, has several version compatible with different active_record versions, so pay attention to the right versioning
32
- if whenever you specify versions manually.
33
-
34
26
  Add this line to your application's Gemfile:
35
27
 
36
28
  ```ruby
37
- gem 'rails_sql_prettifier', '~> X.X.X'
29
+ gem 'rails_sql_prettifier'
38
30
  ```
39
31
 
40
32
  And then execute:
@@ -51,14 +43,12 @@ Or install it yourself as:
51
43
 
52
44
  ```ruby
53
45
  Niceql.configure do |c|
54
- # Setting pg_adapter_with_nicesql to true will APPLY formatting SQL queries
46
+ # Setting pg_adapter_with_nicesql to true will force formatting SQL queries
55
47
  # before execution. Formatted SQL will lead to much better SQL-query debugging and much more clearer error messages
56
48
  # if you are using Postgresql as a data source.
49
+ # BUT do not use it in production until https://github.com/alekseyl/niceql/issues/16 is resolved
57
50
  #
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
51
+ # You can adjust pg_adapter in production but do it at your own risk!
62
52
  #
63
53
  # If you need to debug SQL queries in production use exec_niceql
64
54
  #
@@ -105,7 +95,7 @@ end
105
95
  # only formatting without colorization, you can run output of to_niceql as a SQL query in connection.execute
106
96
  Model.scope.to_niceql
107
97
 
108
- # will run prettified sql and hence will properly prettify PG errors if scope runs with any
98
+ # prettify PG errors if scope runs with any
109
99
  Model.scope_with_err.exec_niceql
110
100
  ```
111
101
 
@@ -159,10 +149,7 @@ end
159
149
  If your console support more colors or different schemes, or if you prefer different colorization, then you can override ColorizeString methods.
160
150
  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.
161
151
 
162
- ## Testing
163
- ```bash
164
- docker-compose up
165
- ```
152
+ ##
166
153
 
167
154
  ## Contributing
168
155
 
@@ -1,3 +1,3 @@
1
1
  module RailsSQLPrettifier
2
- VERSION = '5.0.5'
2
+ VERSION = '6.0.2'
3
3
  end
@@ -2,8 +2,8 @@ require "rails_sql_prettifier/version"
2
2
  require 'active_record'
3
3
  require "niceql"
4
4
 
5
-
6
5
  module RailsSQLPrettifier
6
+ include Niceql
7
7
 
8
8
  module ArExtentions
9
9
  def exec_niceql
@@ -28,13 +28,11 @@ module RailsSQLPrettifier
28
28
  end
29
29
 
30
30
  module AbstractAdapterLogPrettifier
31
- private
32
- def log( sql, *args, **kwargs, &block )
31
+ def log( sql, *args, &block )
33
32
  # \n need to be placed because AR log will start with action description + time info.
34
33
  # rescue sql - just to be sure Prettifier wouldn't break production
35
34
  formatted_sql = "\n" + Niceql::Prettifier.prettify_sql(sql) rescue sql
36
-
37
- super( formatted_sql, *args, **kwargs, &block )
35
+ super( formatted_sql, *args, &block )
38
36
  end
39
37
  end
40
38
 
@@ -46,7 +44,7 @@ module RailsSQLPrettifier
46
44
  end
47
45
  end
48
46
 
49
- module NiceQLConfigExt
47
+ module ARNiceQLConfig
50
48
  extend ActiveSupport::Concern
51
49
 
52
50
  included do
@@ -66,26 +64,17 @@ module RailsSQLPrettifier
66
64
  self.prettify_active_record_log_output = false
67
65
  self.prettify_pg_errors = ar_using_pg_adapter?
68
66
  end
69
- end
70
-
71
- module NiceqlExt
72
- def configure
73
- super
74
67
 
75
- if config.pg_adapter_with_nicesql && defined?(::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter) && !protected_env?
76
- ::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.include(PostgresAdapterNiceQL)
77
- end
68
+ module ClassMethods
69
+ def configure
70
+ super
78
71
 
79
- ::ActiveRecord::ConnectionAdapters::AbstractAdapter.prepend( AbstractAdapterLogPrettifier ) if config.prettify_active_record_log_output
72
+ ::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.include(PostgresAdapterNiceQL) if config.pg_adapter_with_nicesql
80
73
 
81
- ::ActiveRecord::StatementInvalid.include( RailsSQLPrettifier::ErrorExt ) if config.prettify_pg_errors && config.ar_using_pg_adapter?
82
- end
83
- end
74
+ ::ActiveRecord::ConnectionAdapters::AbstractAdapter.prepend( AbstractAdapterLogPrettifier ) if config.prettify_active_record_log_output
84
75
 
85
- module ProtectedEnv
86
- def protected_env?
87
- ActiveRecord::Base.connection.migration_context.protected_environment? ||
88
- defined?(Rails) && !(Rails.env.test? || Rails.env.development?)
76
+ ::ActiveRecord::StatementInvalid.include( Niceql::ErrorExt ) if config.prettify_pg_errors && config.ar_using_pg_adapter?
77
+ end
89
78
  end
90
79
  end
91
80
 
@@ -93,9 +82,5 @@ module RailsSQLPrettifier
93
82
  ::Arel::TreeManager,
94
83
  ::Arel::Nodes::Node].each { |klass| klass.send(:include, ArExtentions) }
95
84
 
96
- Niceql::NiceQLConfig.include( NiceQLConfigExt )
97
-
98
- # we need to use a prepend otherwise it's not preceding Niceql.configure in a lookup chain
99
- Niceql.singleton_class.prepend( NiceqlExt )
100
- Niceql.extend(ProtectedEnv)
85
+ NiceQLConfig.include( ARNiceQLConfig )
101
86
  end
@@ -31,19 +31,15 @@ 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.6'
34
+ spec.add_dependency "niceql", '~> 0.5'
35
35
 
36
- spec.add_dependency "activerecord", "< 6.0"
36
+ spec.add_development_dependency "activerecord", '>= 6.0', '< 6.1'
37
37
 
38
38
  spec.add_development_dependency "bundler", ">= 1"
39
39
  spec.add_development_dependency "rake", ">= 12.3.3"
40
40
  spec.add_development_dependency "minitest", "~> 5.0"
41
41
 
42
- spec.add_development_dependency "awesome_print"
43
42
  spec.add_development_dependency "differ", '~> 0.1'
44
43
  spec.add_development_dependency "pry-byebug", '~> 3.9'
45
44
  spec.add_development_dependency 'sqlite3', '~> 1'
46
- spec.add_development_dependency 'pg', '~> 1'
47
-
48
- spec.add_development_dependency 'stubberry', '~> 0.2'
49
45
  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: 5.0.5
4
+ version: 6.0.2
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: 2022-01-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: niceql
@@ -16,28 +16,34 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.6'
19
+ version: '0.5'
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.6'
26
+ version: '0.5'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activerecord
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "<"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '6.0'
34
- type: :runtime
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: '6.1'
37
+ type: :development
35
38
  prerelease: false
36
39
  version_requirements: !ruby/object:Gem::Requirement
37
40
  requirements:
38
- - - "<"
41
+ - - ">="
39
42
  - !ruby/object:Gem::Version
40
43
  version: '6.0'
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: '6.1'
41
47
  - !ruby/object:Gem::Dependency
42
48
  name: bundler
43
49
  requirement: !ruby/object:Gem::Requirement
@@ -80,20 +86,6 @@ dependencies:
80
86
  - - "~>"
81
87
  - !ruby/object:Gem::Version
82
88
  version: '5.0'
83
- - !ruby/object:Gem::Dependency
84
- name: awesome_print
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - ">="
88
- - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: '0'
97
89
  - !ruby/object:Gem::Dependency
98
90
  name: differ
99
91
  requirement: !ruby/object:Gem::Requirement
@@ -136,34 +128,6 @@ dependencies:
136
128
  - - "~>"
137
129
  - !ruby/object:Gem::Version
138
130
  version: '1'
139
- - !ruby/object:Gem::Dependency
140
- name: pg
141
- requirement: !ruby/object:Gem::Requirement
142
- requirements:
143
- - - "~>"
144
- - !ruby/object:Gem::Version
145
- version: '1'
146
- type: :development
147
- prerelease: false
148
- version_requirements: !ruby/object:Gem::Requirement
149
- requirements:
150
- - - "~>"
151
- - !ruby/object:Gem::Version
152
- version: '1'
153
- - !ruby/object:Gem::Dependency
154
- name: stubberry
155
- requirement: !ruby/object:Gem::Requirement
156
- requirements:
157
- - - "~>"
158
- - !ruby/object:Gem::Version
159
- version: '0.2'
160
- type: :development
161
- prerelease: false
162
- version_requirements: !ruby/object:Gem::Requirement
163
- requirements:
164
- - - "~>"
165
- - !ruby/object:Gem::Version
166
- version: '0.2'
167
131
  description: 'This is an ActiveRecord integration for the SQL prettifier gem niceql. '
168
132
  email:
169
133
  - leshchuk@gmail.com
@@ -171,21 +135,17 @@ executables: []
171
135
  extensions: []
172
136
  extra_rdoc_files: []
173
137
  files:
174
- - ".byebug_history"
175
138
  - ".gitignore"
176
139
  - ".ruby-gemset"
177
140
  - ".ruby-version"
178
141
  - ".travis.yml"
179
142
  - CHANGELOG.md
180
- - Dockerfile
181
- - Dockerfile_30
182
143
  - Gemfile
183
144
  - LICENSE.txt
184
145
  - README.md
185
146
  - Rakefile
186
147
  - bin/console
187
148
  - bin/setup
188
- - docker-compose.yml
189
149
  - err_now.png
190
150
  - err_was.png
191
151
  - lib/benchmark/cat.rb
data/.byebug_history DELETED
@@ -1,40 +0,0 @@
1
- exit
2
- ActiveRecord::Base.connection_config[:adapter]
3
- ActiveRecord::Base.connection_config.adapter
4
- ActiveRecord::Base.connection_config
5
- c
6
- ActiveRecord.version <= Gem::Version.new(5)
7
- c
8
- ActiveRecord.version
9
- exit
10
- ActiveRecord.version
11
- c
12
- exit
13
- si.sql
14
- si
15
- c
16
- sql_body
17
- n
18
- s
19
- original_sql_query
20
- err
21
- s
22
- up
23
- s
24
- up
25
- s
26
- up
27
- s
28
- super
29
- try(:sql)
30
- Niceql.config.prettify_pg_errors
31
- c
32
- exit
33
- err_template
34
- si.to_s
35
- exit
36
- err_caret_line
37
- err_quote_caret_offset
38
- c
39
- err.lines[1].index( '...' ).to_i
40
- err_caret_line
data/Dockerfile DELETED
@@ -1,20 +0,0 @@
1
- FROM ruby:2.7.5-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/Dockerfile_30 DELETED
@@ -1,20 +0,0 @@
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/docker-compose.yml DELETED
@@ -1,19 +0,0 @@
1
- version: "3.7"
2
-
3
- services:
4
- test:
5
- build: .
6
- image: rsp_5_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_5_3_0
16
- command: /bin/bash -c 'service postgresql start && rake test'
17
- volumes:
18
- - '.:/app'
19
-