pp_sql 0.2.9 → 0.2.10

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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +23 -5
  3. data/lib/pp_sql.rb +8 -0
  4. data/lib/pp_sql/version.rb +1 -1
  5. metadata +13 -14
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 195ee7e1114d5ba688ae06a9b1a2e445d7bf152332c270a61a754856856630f1
4
- data.tar.gz: b1a36b7dedbed342094fc01a63897ae15fb92c19d717abcfe9dd7a78a8e1320f
3
+ metadata.gz: 4b5841217cf6f56727889b830d7023111f408697089c85d7a911eac67d06fd24
4
+ data.tar.gz: 3ecd625cd658883493fc4d717006bfbce31c17fa075eb740b8b0d5277f06e1f9
5
5
  SHA512:
6
- metadata.gz: f384091566d5227ebc92d82f24b901d93a84cda413eefdc49d29583c54b6c7e94bfdec7cc7bd3c90ecd68ff47d97ae85236093ec5b7268ceeddbe04b1c1b3ea9
7
- data.tar.gz: 1a9160498ac0a8708ea88114ad3f51c9fca3863a9d9f09a8063d5bf84c1dab9b6419f24287a06054f6e0bcb80138a63d3da57db5efd3691293003fbf97d5d72f
6
+ metadata.gz: bd05589663ee26cbaebe265e537f6b2e383d419861f6c0a2c189a6931df9803ef89c60040a4c30ffac8d1315e7f9a14b16ed049b1f9f2d458bc7d535aa391699
7
+ data.tar.gz: 4a75d4fd39d931ecdc133972a08b06c99b60dee95b5b50b3c99dcb1e534c21201a1199029db7afa835f3d32b6c0340aacb1c7e04c6f41ba7cb40c4e6316ad974
data/README.md CHANGED
@@ -1,8 +1,11 @@
1
- # PpSql [![Build Status](https://travis-ci.org/kvokka/pp_sql.svg?branch=master)](https://travis-ci.org/kvokka/pp_sql)
1
+ # PpSql
2
+ [![Build Status](https://travis-ci.org/kvokka/pp_sql.svg?branch=master)](https://travis-ci.org/kvokka/pp_sql)
3
+ [![Codacy Badge](https://api.codacy.com/project/badge/Grade/7c866da60b1b4dd78eacc379cc0e7f3b)](https://www.codacy.com/app/kvokka/pp_sql?utm_source=github.com&utm_medium=referral&utm_content=kvokka/pp_sql&utm_campaign=Badge_Grade)
4
+ [![Reviewed by Hound](https://img.shields.io/badge/Reviewed_by-Hound-8E64B0.svg)](https://houndci.com)
2
5
 
3
- Replace standard `ActiveRecord#to_sql` method with
6
+ Replace standard `ActiveRecord#to_sql` method with
4
7
  [`anbt-sql-formatter`](https://github.com/sonota88/anbt-sql-formatter)
5
- gem for pretty SQL code output in console. Rails log will be formatted also.
8
+ gem for pretty SQL code output in console. Rails log will be formatted also.
6
9
  Example output:
7
10
 
8
11
  ![log](https://raw.githubusercontent.com/kvokka/pp_sql/master/screenshots/log.png)
@@ -53,7 +56,7 @@ $ bundle
53
56
 
54
57
  ## With other formatters
55
58
 
56
- If you are `pry` user, or use custom output formatter, use `puts` for output whitespaces,
59
+ If you are `pry` user, or use custom output formatter, use `puts` for output whitespaces,
57
60
  like `puts User.all.to_sql`, or use `User.all.pp_sql`.
58
61
 
59
62
  ## With Rails
@@ -61,6 +64,21 @@ like `puts User.all.to_sql`, or use `User.all.pp_sql`.
61
64
  If you do not want to rewrite default `#to_sql` method you may specify
62
65
  `PpSql.rewrite_to_sql_method=false` in initializers.
63
66
 
67
+ You can also disable log formatting by specifying `PpSql.add_rails_logger_formatting=false`
68
+ in initializers.
69
+
70
+ ### Add to Application record
71
+
72
+ I found usefull this trick:
73
+
74
+ ```
75
+ class ApplicationRecord < ActiveRecord::Base
76
+ include PpSql::ToSqlBeautify if defined?(Rails::Console)
77
+
78
+ self.abstract_class = true
79
+ end
80
+ ```
81
+
64
82
  ## License
65
- The gem is available as open source under the terms of the
83
+ The gem is available as open source under the terms of the
66
84
  [MIT License](http://opensource.org/licenses/MIT).
data/lib/pp_sql.rb CHANGED
@@ -5,14 +5,17 @@ module PpSql
5
5
  # you may switch this setting to false in initializer
6
6
  class << self
7
7
  attr_accessor :rewrite_to_sql_method
8
+ attr_accessor :add_rails_logger_formatting
8
9
  end
9
10
  self.rewrite_to_sql_method = true
11
+ self.add_rails_logger_formatting = true
10
12
 
11
13
  module Formatter
12
14
  private
13
15
 
14
16
  def _sql_formatter
15
17
  return @_sql_formatter if defined?(@_sql_formatter) && @_sql_formatter
18
+
16
19
  require 'anbt-sql-formatter/formatter'
17
20
  rule = AnbtSql::Rule.new
18
21
  rule.keyword = AnbtSql::Rule::KEYWORD_UPPER_CASE
@@ -26,6 +29,7 @@ module PpSql
26
29
  def to_sql
27
30
  return self unless ::PpSql.rewrite_to_sql_method || defined?(super)
28
31
  return super unless ::PpSql.rewrite_to_sql_method
32
+
29
33
  extend Formatter
30
34
  _sql_formatter.format(defined?(super) ? super.dup : dup)
31
35
  end
@@ -43,6 +47,7 @@ module PpSql
43
47
 
44
48
  module Rails5PpSqlExtraction
45
49
  # export from Rails 5 with for Rails 4.2+ versions
50
+
46
51
  private
47
52
 
48
53
  def colorize_payload_name(name, payload_name)
@@ -69,7 +74,10 @@ module PpSql
69
74
 
70
75
  module LogSubscriberPrettyPrint
71
76
  include Formatter
77
+
72
78
  def sql(event)
79
+ return super event unless ::PpSql.add_rails_logger_formatting
80
+
73
81
  e = event.dup
74
82
  e.payload[:sql] = _sql_formatter.format(e.payload[:sql].dup)
75
83
  super e
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PpSql
4
- VERSION = '0.2.9'
4
+ VERSION = '0.2.10'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pp_sql
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.9
4
+ version: 0.2.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kvokka
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-29 00:00:00.000000000 Z
11
+ date: 2019-03-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: anbt-sql-formatter
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.0.5
19
+ version: 0.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.0.5
26
+ version: 0.0.6
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rails
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -140,30 +140,30 @@ dependencies:
140
140
  name: rubocop
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - ">="
143
+ - - "~>"
144
144
  - !ruby/object:Gem::Version
145
- version: '0'
145
+ version: 0.65.0
146
146
  type: :development
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
- - - ">="
150
+ - - "~>"
151
151
  - !ruby/object:Gem::Version
152
- version: '0'
152
+ version: 0.65.0
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: sqlite3
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
- - - ">="
157
+ - - "~>"
158
158
  - !ruby/object:Gem::Version
159
- version: '0'
159
+ version: 1.3.6
160
160
  type: :development
161
161
  prerelease: false
162
162
  version_requirements: !ruby/object:Gem::Requirement
163
163
  requirements:
164
- - - ">="
164
+ - - "~>"
165
165
  - !ruby/object:Gem::Version
166
- version: '0'
166
+ version: 1.3.6
167
167
  description: Helps to save your eyes, when reading hardcore SQL requests in console
168
168
  email:
169
169
  - kvokka@yahoo.com
@@ -195,8 +195,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
195
195
  - !ruby/object:Gem::Version
196
196
  version: '0'
197
197
  requirements: []
198
- rubyforge_project:
199
- rubygems_version: 2.7.3
198
+ rubygems_version: 3.0.1
200
199
  signing_key:
201
200
  specification_version: 4
202
201
  summary: Beautify SQL output of ActiveRecord#to_sql