rails_sql_prettifier 6.1.1 → 7.0.3

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: 459c1f20e82eb14b0130418cb1161272383ae9f9f902164100b2a4d81bbabb9c
4
- data.tar.gz: db5ee936e31bd470ac74940b2fa086e4a1aec84004cb05971c6434e8f5cb2ea1
3
+ metadata.gz: e25116da08165fe68232d88629379f8e8cb48c503ad73926119d1906ee0a45d6
4
+ data.tar.gz: 3efe5e251b908df04d3e551c2a7318405cbd9392d818652db85cd73165fa4a9f
5
5
  SHA512:
6
- metadata.gz: a159e5b627abaa4ac80c70092668aad54f11f871c13a57e83585e38851d2f522273653d79871b2b087d1bce83de00c9119b6b2d7c28b60d7b75c8b13b1e3dde1
7
- data.tar.gz: 4feabc414ccf282a7462c44527514449735b8bcdf9b2b84afe3b873735176cecbe1dcc40dfa6745b67af114391a1a38808cc3658bae4e45e8b242267932e32ce
6
+ metadata.gz: 78ea21d51cd7cad7b59599979a9529f7ca4173709b758b3ab4eecf2aea49e53644d7399ee303ef42d0789454a88abec6a422b9ec6b6108bc1251e15fb6216d18
7
+ data.tar.gz: 1958bdd7757d0d51d4b54e3d8eef556c4b42f7a18ac914677c7f8130c76c86a40627c8c251bbdbe9a6394c1f224b4aa53401d9968410fec49c89098354887153
data/.gitignore CHANGED
@@ -8,4 +8,5 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  /inspectionProfiles/
11
- .idea
11
+ .idea
12
+ .byebug_history
data/.ruby-gemset CHANGED
@@ -1 +1 @@
1
- rails_sql_prettifier_ar_6
1
+ rails_sql_prettifier
data/CHANGELOG.md CHANGED
@@ -1,8 +1,9 @@
1
- # 6.1.0
1
+ #7.0.3
2
+ * fixed issue [#20](https://github.com/alekseyl/niceql/issues/20)
3
+ * adding support for multiple ruby versions testing using docker-compose
2
4
 
3
- * This a active record prior to 7.0 version and >= 6.1 compatible niceql integration
4
- ar < 6.0:
5
- * StatementInvalid initialization, starting version 6 it has named param sql: for original query )
6
-
7
- ar <= 6.1:
8
- * Starting from 6.1 connection_db_config used as standalone object instead of connection_config
5
+ #7.0.2
6
+ * active record versioning is properly aligned now
7
+
8
+ #7.0.0
9
+ * current master branch
data/Dockerfile ADDED
@@ -0,0 +1,20 @@
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 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
@@ -1,7 +1,12 @@
1
1
  # RailsSQLPrettifier
2
2
 
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.
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 )
5
10
 
6
11
  Any reasonable suggestions are welcome.
7
12
 
@@ -23,10 +28,13 @@ after:
23
28
 
24
29
  ## Installation
25
30
 
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
+
26
34
  Add this line to your application's Gemfile:
27
35
 
28
36
  ```ruby
29
- gem 'rails_sql_prettifier'
37
+ gem 'rails_sql_prettifier', '~> X.X.X'
30
38
  ```
31
39
 
32
40
  And then execute:
@@ -86,8 +94,6 @@ end
86
94
 
87
95
  ## Usage
88
96
 
89
- ### With ActiveRecord
90
-
91
97
  ```ruby
92
98
  # puts colorized and formatted corresponding SQL query
93
99
  Model.scope.niceql
@@ -149,7 +155,10 @@ end
149
155
  If your console support more colors or different schemes, or if you prefer different colorization, then you can override ColorizeString methods.
150
156
  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.
151
157
 
152
- ##
158
+ ## Testing
159
+ ```bash
160
+ docker-compose up
161
+ ```
153
162
 
154
163
  ## Contributing
155
164
 
@@ -0,0 +1,18 @@
1
+ version: "3.7"
2
+
3
+ services:
4
+ test:
5
+ build: .
6
+ image: niceql
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: niceql_3_0
16
+ command: /bin/bash -c 'service postgresql start && rake test'
17
+ volumes:
18
+ - '.:/app'
@@ -1,3 +1,3 @@
1
1
  module RailsSQLPrettifier
2
- VERSION = '6.1.1'
2
+ VERSION = '7.0.3'
3
3
  end
@@ -2,8 +2,8 @@ require "rails_sql_prettifier/version"
2
2
  require 'active_record'
3
3
  require "niceql"
4
4
 
5
+
5
6
  module RailsSQLPrettifier
6
- include Niceql
7
7
 
8
8
  module ArExtentions
9
9
  def exec_niceql
@@ -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
 
@@ -44,7 +46,7 @@ module RailsSQLPrettifier
44
46
  end
45
47
  end
46
48
 
47
- module ARNiceQLConfig
49
+ module NiceQLConfigExt
48
50
  extend ActiveSupport::Concern
49
51
 
50
52
  included do
@@ -53,7 +55,6 @@ module RailsSQLPrettifier
53
55
  :prettify_pg_errors
54
56
  end
55
57
 
56
-
57
58
  def ar_using_pg_adapter?
58
59
  ActiveRecord::Base.connection_db_config.adapter == 'postgresql'
59
60
  end
@@ -64,17 +65,19 @@ module RailsSQLPrettifier
64
65
  self.prettify_active_record_log_output = false
65
66
  self.prettify_pg_errors = ar_using_pg_adapter?
66
67
  end
68
+ end
67
69
 
68
- module ClassMethods
69
- def configure
70
- super
70
+ module NiceqlExt
71
+ def configure
72
+ super
71
73
 
72
- ::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.include(PostgresAdapterNiceQL) if config.pg_adapter_with_nicesql
74
+ if config.pg_adapter_with_nicesql && defined?( ::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter )
75
+ ::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.include( PostgresAdapterNiceQL)
76
+ end
73
77
 
74
- ::ActiveRecord::ConnectionAdapters::AbstractAdapter.prepend( AbstractAdapterLogPrettifier ) if config.prettify_active_record_log_output
78
+ ::ActiveRecord::ConnectionAdapters::AbstractAdapter.prepend( AbstractAdapterLogPrettifier ) if config.prettify_active_record_log_output
75
79
 
76
- ::ActiveRecord::StatementInvalid.include( Niceql::ErrorExt ) if config.prettify_pg_errors && config.ar_using_pg_adapter?
77
- end
80
+ ::ActiveRecord::StatementInvalid.include( RailsSQLPrettifier::ErrorExt ) if config.prettify_pg_errors && config.ar_using_pg_adapter?
78
81
  end
79
82
  end
80
83
 
@@ -82,5 +85,8 @@ module RailsSQLPrettifier
82
85
  ::Arel::TreeManager,
83
86
  ::Arel::Nodes::Node].each { |klass| klass.send(:include, ArExtentions) }
84
87
 
85
- NiceQLConfig.include( ARNiceQLConfig )
88
+ Niceql::NiceQLConfig.include( NiceQLConfigExt )
89
+
90
+ # we need to use a prepend otherwise it's not preceding Niceql.configure in a lookup chain
91
+ Niceql.singleton_class.prepend( NiceqlExt )
86
92
  end
@@ -32,14 +32,17 @@ Gem::Specification.new do |spec|
32
32
 
33
33
  spec.required_ruby_version = '>= 2.4'
34
34
  spec.add_dependency "niceql", '~> 0.5'
35
-
36
- spec.add_development_dependency "activerecord", '>= 6.1', '< 7'
35
+ spec.add_dependency "activerecord", '>= 7'
37
36
 
38
37
  spec.add_development_dependency "bundler", ">= 1"
39
38
  spec.add_development_dependency "rake", ">= 12.3.3"
40
39
  spec.add_development_dependency "minitest", "~> 5.0"
41
40
 
41
+ spec.add_development_dependency "awesome_print"
42
42
  spec.add_development_dependency "differ", '~> 0.1'
43
43
  spec.add_development_dependency "pry-byebug", '~> 3.9'
44
44
  spec.add_development_dependency 'sqlite3', '~> 1'
45
+ spec.add_development_dependency 'pg', '~> 1'
46
+
47
+ spec.add_development_dependency 'stubberry', '~> 0.2'
45
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.1.1
4
+ version: 7.0.3
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-08 00:00:00.000000000 Z
11
+ date: 2022-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: niceql
@@ -29,19 +29,13 @@ dependencies:
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '6.1'
34
- - - "<"
35
32
  - !ruby/object:Gem::Version
36
33
  version: '7'
37
- type: :development
34
+ type: :runtime
38
35
  prerelease: false
39
36
  version_requirements: !ruby/object:Gem::Requirement
40
37
  requirements:
41
38
  - - ">="
42
- - !ruby/object:Gem::Version
43
- version: '6.1'
44
- - - "<"
45
39
  - !ruby/object:Gem::Version
46
40
  version: '7'
47
41
  - !ruby/object:Gem::Dependency
@@ -86,6 +80,20 @@ dependencies:
86
80
  - - "~>"
87
81
  - !ruby/object:Gem::Version
88
82
  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'
89
97
  - !ruby/object:Gem::Dependency
90
98
  name: differ
91
99
  requirement: !ruby/object:Gem::Requirement
@@ -128,6 +136,34 @@ dependencies:
128
136
  - - "~>"
129
137
  - !ruby/object:Gem::Version
130
138
  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'
131
167
  description: 'This is an ActiveRecord integration for the SQL prettifier gem niceql. '
132
168
  email:
133
169
  - leshchuk@gmail.com
@@ -135,18 +171,20 @@ executables: []
135
171
  extensions: []
136
172
  extra_rdoc_files: []
137
173
  files:
138
- - ".byebug_history"
139
174
  - ".gitignore"
140
175
  - ".ruby-gemset"
141
176
  - ".ruby-version"
142
177
  - ".travis.yml"
143
178
  - CHANGELOG.md
179
+ - Dockerfile
180
+ - Dockerfile_30
144
181
  - Gemfile
145
182
  - LICENSE.txt
146
183
  - README.md
147
184
  - Rakefile
148
185
  - bin/console
149
186
  - bin/setup
187
+ - docker-compose.yml
150
188
  - err_now.png
151
189
  - err_was.png
152
190
  - lib/benchmark/cat.rb
data/.byebug_history DELETED
@@ -1,34 +0,0 @@
1
- exit
2
- ActiveRecord::Base.connection_db_config.adapter
3
- ActiveRecord::Base.connection_db_config.adpter
4
- ActiveRecord::Base.connection_db_config
5
- c
6
- exit
7
- si.sql
8
- si
9
- c
10
- sql_body
11
- n
12
- s
13
- original_sql_query
14
- err
15
- s
16
- up
17
- s
18
- up
19
- s
20
- up
21
- s
22
- super
23
- try(:sql)
24
- Niceql.config.prettify_pg_errors
25
- c
26
- exit
27
- err_template
28
- si.to_s
29
- exit
30
- err_caret_line
31
- err_quote_caret_offset
32
- c
33
- err.lines[1].index( '...' ).to_i
34
- err_caret_line