niceql 0.1.14 → 0.1.15
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 +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/niceql/version.rb +1 -1
- data/lib/niceql.rb +18 -7
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e7919448f67585220d4fd6aaa4fd779558acf89c
|
4
|
+
data.tar.gz: 6c6ee86d5794ccaed63eade5c6cd0c6eb1d9abaa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7abca0d3a40cfdc74105631f3996f87691deb49db0c8580db00a07f42cc480c99700802092d11d03e3f94346da23d29986df9af028902a42a6cf9a1598be8861
|
7
|
+
data.tar.gz: c320c6ad90c99b1b3621aa88c6fa88e8af1655f5eeb18746e7218e3eac6bab1dd722f7d0011314820f3ee69b816b49e34d080e7a1a5bf529e0c65dd4ec3d28a2
|
data/CHANGELOG.md
ADDED
data/lib/niceql/version.rb
CHANGED
data/lib/niceql.rb
CHANGED
@@ -34,7 +34,7 @@ module Niceql
|
|
34
34
|
|
35
35
|
module Prettifier
|
36
36
|
INLINE_VERBS = %w(WITH ASC IN COALESCE AS WHEN THEN ELSE END AND UNION ALL WITH ON DISTINCT INTERSECT EXCEPT EXISTS NOT COUNT ROUND CAST).join('| ')
|
37
|
-
NEW_LINE_VERBS = 'SELECT|FROM|WHERE|CASE|ORDER BY|LIMIT|GROUP BY|LEFT
|
37
|
+
NEW_LINE_VERBS = 'SELECT|FROM|WHERE|CASE|ORDER BY|LIMIT|GROUP BY|(RIGHT |LEFT )*(INNER |OUTER )*JOIN|HAVING|OFFSET|UPDATE'
|
38
38
|
POSSIBLE_INLINER = /(ORDER BY|CASE)/
|
39
39
|
VERBS = "#{INLINE_VERBS}|#{NEW_LINE_VERBS}"
|
40
40
|
STRINGS = /("[^"]+")|('[^']+')/
|
@@ -95,7 +95,7 @@ module Niceql
|
|
95
95
|
#it's better to remove all new lines because it will break formatting
|
96
96
|
sql = sql.gsub("\n", ' ')
|
97
97
|
# remove any additional formatting
|
98
|
-
sql = sql.gsub(/[
|
98
|
+
sql = sql.gsub(/[\s]+/, ' ')
|
99
99
|
|
100
100
|
sql = sql.gsub(STRINGS){ |str| StringColorize.colorize_str(str) } if colorize
|
101
101
|
first_verb = true
|
@@ -137,6 +137,15 @@ module Niceql
|
|
137
137
|
end
|
138
138
|
end
|
139
139
|
|
140
|
+
module AbstractAdapterLogPrettifier
|
141
|
+
def log( sql, *args, &block )
|
142
|
+
# \n need to be placed because AR log will start with action description + time info.
|
143
|
+
# rescue sql - just to be sure Prettifier didn't break production
|
144
|
+
formatted_sql = "\n" + Prettifier.prettify_sql(sql, false) rescue sql
|
145
|
+
super( formatted_sql, *args, &block )
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
140
149
|
module ErrorExt
|
141
150
|
def to_s
|
142
151
|
if ActiveRecord::Base.configurations[Rails.env]['adapter'] == 'postgresql'
|
@@ -148,16 +157,16 @@ module Niceql
|
|
148
157
|
end
|
149
158
|
|
150
159
|
class NiceQLConfig
|
151
|
-
attr_accessor :pg_adapter_with_nicesql
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
attr_accessor :open_bracket_is_newliner
|
160
|
+
attr_accessor :pg_adapter_with_nicesql,
|
161
|
+
:indentation_base,
|
162
|
+
:open_bracket_is_newliner,
|
163
|
+
:prettify_active_record_log_output
|
156
164
|
|
157
165
|
def initialize
|
158
166
|
self.pg_adapter_with_nicesql = false
|
159
167
|
self.indentation_base = 2
|
160
168
|
self.open_bracket_is_newliner = false
|
169
|
+
self.prettify_active_record_log_output = false
|
161
170
|
end
|
162
171
|
end
|
163
172
|
|
@@ -167,6 +176,8 @@ module Niceql
|
|
167
176
|
|
168
177
|
if config.pg_adapter_with_nicesql
|
169
178
|
::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.include(PostgresAdapterNiceQL)
|
179
|
+
elsif config.prettify_active_record_log_output
|
180
|
+
::ActiveRecord::ConnectionAdapters::AbstractAdapter.prepend( AbstractAdapterLogPrettifier )
|
170
181
|
end
|
171
182
|
end
|
172
183
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: niceql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- alekseyl
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-05-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -62,6 +62,7 @@ extra_rdoc_files: []
|
|
62
62
|
files:
|
63
63
|
- ".gitignore"
|
64
64
|
- ".travis.yml"
|
65
|
+
- CHANGELOG.md
|
65
66
|
- Gemfile
|
66
67
|
- LICENSE.txt
|
67
68
|
- README.md
|
@@ -97,7 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
97
98
|
version: '0'
|
98
99
|
requirements: []
|
99
100
|
rubyforge_project:
|
100
|
-
rubygems_version: 2.6.
|
101
|
+
rubygems_version: 2.6.11
|
101
102
|
signing_key:
|
102
103
|
specification_version: 4
|
103
104
|
summary: This is simple and nice sql prettifier, it splits, indent and colorize SQL
|