niceql 0.1.14 → 0.1.15

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
  SHA1:
3
- metadata.gz: 646d8fcc2c3fa42bacdef1e4de6a86dd63c3aea9
4
- data.tar.gz: 1ca41e47438ed32b4085e3bb4c7e7e2364ec0c39
3
+ metadata.gz: e7919448f67585220d4fd6aaa4fd779558acf89c
4
+ data.tar.gz: 6c6ee86d5794ccaed63eade5c6cd0c6eb1d9abaa
5
5
  SHA512:
6
- metadata.gz: df6a132d674f8afc0d95d2596043b93c87a01e38ef1ffadea72fd80a02318f20bb6bc1657334b1f3b63e7458a61ae906940c7892e23f2023e8a86882acc1e2f9
7
- data.tar.gz: 1e5039d4c982d4aa3fa00f816dab4b181edcfdcc13ddd0599287671038b7b40a9fe7f4aabf1f15120358578e1b53d9304f539ee19697f62a3c9d4747e2e028d7
6
+ metadata.gz: 7abca0d3a40cfdc74105631f3996f87691deb49db0c8580db00a07f42cc480c99700802092d11d03e3f94346da23d29986df9af028902a42a6cf9a1598be8861
7
+ data.tar.gz: c320c6ad90c99b1b3621aa88c6fa88e8af1655f5eeb18746e7218e3eac6bab1dd722f7d0011314820f3ee69b816b49e34d080e7a1a5bf529e0c65dd4ec3d28a2
data/CHANGELOG.md ADDED
@@ -0,0 +1,4 @@
1
+ # 0.1.15
2
+ * JOIN verb refactored, INNER|OUTER will be also colored properly
3
+ * prettify_active_record_log_output added to config, now you can set it to true
4
+ and sql will log prettified
@@ -1,3 +1,3 @@
1
1
  module Niceql
2
- VERSION = "0.1.14"
2
+ VERSION = "0.1.15"
3
3
  end
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 JOIN|RIGHT JOIN|JOIN|HAVING|OFFSET|UPDATE'
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
- attr_accessor :indentation_base
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.14
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: 2017-09-14 00:00:00.000000000 Z
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.13
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