rails-flog 1.4.0 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +2 -0
- data/.travis.yml +5 -16
- data/README.md +3 -2
- data/gemfiles/{rails_4_0_x.gemfile → rails_5_2_x.gemfile} +1 -1
- data/lib/flog/configuration.rb +10 -2
- data/lib/flog/sql_formattable.rb +4 -2
- data/lib/flog/version.rb +1 -1
- data/rails-flog.gemspec +2 -2
- data/test/unit/sql_formattable_test.rb +74 -11
- metadata +8 -10
- data/gemfiles/rails_3_2_x.gemfile +0 -10
- data/gemfiles/rails_4_1_x.gemfile +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a916ad1e90e6cc5129639360c15c13638e014c5c3ab60ae03e5a68b38f8601e5
|
4
|
+
data.tar.gz: 271eab7f87be9bb46ffdb028732bd244f76b933b1fe6bda290b199050cdbee68
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f8b98fff00f12bb337573c9fe988e65596d6ce76ffd43defc7b5651286675049741b41d6dd03f3da6216e3b68e371f2bce60b1173c8ec3175a0a91be12d98cd
|
7
|
+
data.tar.gz: cfe53e680ac6ed2d86eee1e30e14350bbdfe00bbb7e9910345aef5b72ee20bb9d6766870d1c7a3747014dbb2758379b7b1447c5f38ba6540e21ec95f8d8de7a5
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -1,25 +1,14 @@
|
|
1
1
|
language: ruby
|
2
2
|
sudo: false
|
3
|
+
branches:
|
4
|
+
only:
|
5
|
+
- master
|
3
6
|
rvm:
|
4
|
-
- 2.0
|
5
|
-
- 2.1
|
6
|
-
- 2.2
|
7
7
|
- 2.3
|
8
8
|
- 2.4
|
9
|
+
- 2.5
|
9
10
|
gemfile:
|
10
|
-
- gemfiles/rails_3_2_x.gemfile
|
11
|
-
- gemfiles/rails_4_0_x.gemfile
|
12
|
-
- gemfiles/rails_4_1_x.gemfile
|
13
11
|
- gemfiles/rails_4_2_x.gemfile
|
14
12
|
- gemfiles/rails_5_0_x.gemfile
|
15
13
|
- gemfiles/rails_5_1_x.gemfile
|
16
|
-
|
17
|
-
exclude:
|
18
|
-
- gemfile: gemfiles/rails_5_0_x.gemfile
|
19
|
-
rvm: 2.0
|
20
|
-
- gemfile: gemfiles/rails_5_0_x.gemfile
|
21
|
-
rvm: 2.1
|
22
|
-
- gemfile: gemfiles/rails_5_1_x.gemfile
|
23
|
-
rvm: 2.0
|
24
|
-
- gemfile: gemfiles/rails_5_1_x.gemfile
|
25
|
-
rvm: 2.1
|
14
|
+
- gemfiles/rails_5_2_x.gemfile
|
data/README.md
CHANGED
@@ -126,8 +126,8 @@ Priority of this feature is higher than configurations.
|
|
126
126
|
|
127
127
|
## Supported versions
|
128
128
|
|
129
|
-
- Ruby: 2.
|
130
|
-
- Rails:
|
129
|
+
- Ruby: 2.3.x, 2.4.x, 2.5.x
|
130
|
+
- Rails: 4.2.x, 5.0.x, 5.1.x, 5.2.x
|
131
131
|
|
132
132
|
## Contributing
|
133
133
|
|
@@ -148,3 +148,4 @@ Priority of this feature is higher than configurations.
|
|
148
148
|
- v1.3.2 (2014-04-28 JST): Confirm with Rails 4.1
|
149
149
|
- v1.3.3 (2015-11-16 JST): Confirm with Rails 4.2
|
150
150
|
- v1.4.0 (2017-10-01 JST): Compatible for Rails 5.0 and Rails 5.1, and dropped Ruby 1.9.3 support
|
151
|
+
- v1.5.0 (2018-12-19 JST): Add `sql_indenti` and `sql_in_values_num` options, and dropped eol rails versions.
|
data/lib/flog/configuration.rb
CHANGED
@@ -1,13 +1,19 @@
|
|
1
|
+
require "anbt-sql-formatter/rule"
|
2
|
+
|
1
3
|
module Flog
|
4
|
+
ONELINE_IN_VALUES_NUM = ::AnbtSql::Rule::ONELINE_IN_VALUES_NUM
|
5
|
+
|
2
6
|
class Configuration
|
3
7
|
attr_writer :ignore_cached_query, :force_on_nested_params
|
4
|
-
attr_accessor :query_duration_threshold, :params_key_count_threshold
|
8
|
+
attr_accessor :query_duration_threshold, :params_key_count_threshold, :sql_indent, :sql_in_values_num
|
5
9
|
|
6
10
|
def initialize
|
7
11
|
@ignore_cached_query = true
|
8
12
|
@query_duration_threshold = 0.0
|
9
13
|
@params_key_count_threshold = 1
|
10
14
|
@force_on_nested_params = true
|
15
|
+
@sql_indent = "\t"
|
16
|
+
@sql_in_values_num = 1
|
11
17
|
end
|
12
18
|
|
13
19
|
def ignore_cached_query?
|
@@ -24,6 +30,8 @@ module Flog
|
|
24
30
|
end
|
25
31
|
|
26
32
|
def self.configure
|
27
|
-
|
33
|
+
cfg = Flog::Configuration.new
|
34
|
+
yield(cfg) if block_given?
|
35
|
+
@@config = cfg
|
28
36
|
end
|
29
37
|
end
|
data/lib/flog/sql_formattable.rb
CHANGED
@@ -9,22 +9,24 @@ module Flog::SqlFormattable
|
|
9
9
|
|
10
10
|
formatted = format_sql(event.payload[:sql])
|
11
11
|
|
12
|
-
shunt_payload_value(event.payload, :sql, "\n
|
12
|
+
shunt_payload_value(event.payload, :sql, "\n#{Flog.config.sql_indent}#{formatted}") do
|
13
13
|
super(event)
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
17
|
private
|
18
|
+
|
18
19
|
def format_sql(sql)
|
19
20
|
return sql if sql.blank?
|
20
21
|
|
21
22
|
require "anbt-sql-formatter/formatter"
|
22
23
|
rule = AnbtSql::Rule.new
|
23
24
|
rule.keyword = AnbtSql::Rule::KEYWORD_UPPER_CASE
|
25
|
+
rule.indent_string = Flog.config.sql_indent
|
26
|
+
rule.in_values_num = Flog.config.sql_in_values_num
|
24
27
|
%w(count sum).each do |function_name|
|
25
28
|
rule.function_names << function_name
|
26
29
|
end
|
27
|
-
rule.indent_string = "\t"
|
28
30
|
AnbtSql::Formatter.new(rule).format(sql.squeeze(" "))
|
29
31
|
end
|
30
32
|
|
data/lib/flog/version.rb
CHANGED
data/rails-flog.gemspec
CHANGED
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_development_dependency "minitest"
|
25
25
|
spec.add_development_dependency "coveralls"
|
26
26
|
|
27
|
-
spec.add_dependency "rails", ">=
|
28
|
-
spec.add_dependency "anbt-sql-formatter"
|
27
|
+
spec.add_dependency "rails", ">=4.2.0"
|
28
|
+
spec.add_dependency "anbt-sql-formatter", ">=0.0.7"
|
29
29
|
spec.add_dependency "awesome_print"
|
30
30
|
end
|
@@ -32,13 +32,12 @@ class SqlFormattableTest < ActiveSupport::TestCase
|
|
32
32
|
def test_sql_is_formatted
|
33
33
|
Book.where(category: "comics").to_a
|
34
34
|
assert_logger do |logger|
|
35
|
-
|
36
|
-
assert_equal %{
|
37
|
-
assert_equal %{
|
38
|
-
assert_equal %{
|
39
|
-
assert_equal %{
|
40
|
-
|
41
|
-
assert logs[6].start_with?(%{ "books" . "category" = })
|
35
|
+
assert_equal %{\tSELECT} , logger.debugs[1]
|
36
|
+
assert_equal %{\t\t"books" . *}, logger.debugs[2]
|
37
|
+
assert_equal %{\tFROM} , logger.debugs[3]
|
38
|
+
assert_equal %{\t\t"books"} , logger.debugs[4]
|
39
|
+
assert_equal %{\tWHERE} , logger.debugs[5]
|
40
|
+
assert logger.debugs[6].start_with?(%{\t\t"books" . "category" = })
|
42
41
|
end
|
43
42
|
end
|
44
43
|
|
@@ -81,8 +80,7 @@ class SqlFormattableTest < ActiveSupport::TestCase
|
|
81
80
|
Book.where(category: "comics").to_a
|
82
81
|
end
|
83
82
|
assert_logger do |logger|
|
84
|
-
|
85
|
-
logs.each do |log|
|
83
|
+
logger.debugs.each do |log|
|
86
84
|
assert_one_line_sql log if log.include?("CACHE")
|
87
85
|
end
|
88
86
|
end
|
@@ -97,8 +95,7 @@ class SqlFormattableTest < ActiveSupport::TestCase
|
|
97
95
|
Book.where(category: "comics").to_a
|
98
96
|
end
|
99
97
|
assert_logger do |logger|
|
100
|
-
|
101
|
-
logs.each do |log|
|
98
|
+
logger.debugs.each do |log|
|
102
99
|
assert_equal log.include?("SELECT"), false if log.include?("CACHE")
|
103
100
|
end
|
104
101
|
end
|
@@ -114,6 +111,72 @@ class SqlFormattableTest < ActiveSupport::TestCase
|
|
114
111
|
end
|
115
112
|
end
|
116
113
|
|
114
|
+
def test_2space_indent
|
115
|
+
Flog.configure do |config|
|
116
|
+
config.sql_indent = " "
|
117
|
+
end
|
118
|
+
Book.where(category: "comics").to_a
|
119
|
+
assert_logger do |logger|
|
120
|
+
assert_equal %{ SELECT} , logger.debugs[1]
|
121
|
+
assert_equal %{ "books" . *}, logger.debugs[2]
|
122
|
+
assert_equal %{ FROM} , logger.debugs[3]
|
123
|
+
assert_equal %{ "books"} , logger.debugs[4]
|
124
|
+
assert_equal %{ WHERE} , logger.debugs[5]
|
125
|
+
assert logger.debugs[6].start_with?(%{ "books" . "category" = })
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_default_in_values_num
|
130
|
+
Book.where(id: (1..10).to_a).to_a
|
131
|
+
assert_logger do |logger|
|
132
|
+
assert_equal %{\tSELECT} , logger.debugs[1]
|
133
|
+
assert_equal %{\t\t"books" . *} , logger.debugs[2]
|
134
|
+
assert_equal %{\tFROM} , logger.debugs[3]
|
135
|
+
assert_equal %{\t\t"books"} , logger.debugs[4]
|
136
|
+
assert_equal %{\tWHERE} , logger.debugs[5]
|
137
|
+
assert_equal %{\t\t"books" . "id" IN (}, logger.debugs[6]
|
138
|
+
(8..16).each do |l|
|
139
|
+
assert_equal 1, logger.debugs[l].count(",")
|
140
|
+
end
|
141
|
+
assert logger.debugs[17].start_with?(%{\t\t)})
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
def test_in_values_num_set
|
146
|
+
Flog.configure do |config|
|
147
|
+
config.sql_in_values_num = 5
|
148
|
+
end
|
149
|
+
Book.where(id: (1..10).to_a).to_a
|
150
|
+
assert_logger do |logger|
|
151
|
+
assert_equal %{\tSELECT} , logger.debugs[1]
|
152
|
+
assert_equal %{\t\t"books" . *} , logger.debugs[2]
|
153
|
+
assert_equal %{\tFROM} , logger.debugs[3]
|
154
|
+
assert_equal %{\t\t"books"} , logger.debugs[4]
|
155
|
+
assert_equal %{\tWHERE} , logger.debugs[5]
|
156
|
+
assert_equal %{\t\t"books" . "id" IN (}, logger.debugs[6]
|
157
|
+
assert_equal 4, logger.debugs[7].count(",")
|
158
|
+
assert_equal 5, logger.debugs[8].count(",")
|
159
|
+
assert logger.debugs[9].start_with?(%{\t\t)})
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
def test_oneline_in_values
|
164
|
+
Flog.configure do |config|
|
165
|
+
config.sql_in_values_num = Flog::ONELINE_IN_VALUES_NUM
|
166
|
+
end
|
167
|
+
Book.where(id: (1..10).to_a).to_a
|
168
|
+
assert_logger do |logger|
|
169
|
+
assert_equal %{\tSELECT} , logger.debugs[1]
|
170
|
+
assert_equal %{\t\t"books" . *} , logger.debugs[2]
|
171
|
+
assert_equal %{\tFROM} , logger.debugs[3]
|
172
|
+
assert_equal %{\t\t"books"} , logger.debugs[4]
|
173
|
+
assert_equal %{\tWHERE} , logger.debugs[5]
|
174
|
+
assert_equal %{\t\t"books" . "id" IN (}, logger.debugs[6]
|
175
|
+
assert_equal 9, logger.debugs[7].count(",")
|
176
|
+
assert logger.debugs[8].start_with?(%{\t\t)})
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
117
180
|
private
|
118
181
|
def assert_logger(&block)
|
119
182
|
if ActiveRecord::Base.logger.errors.present?
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-flog
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- pinzolo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-12-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -86,28 +86,28 @@ dependencies:
|
|
86
86
|
requirements:
|
87
87
|
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
89
|
+
version: 4.2.0
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
96
|
+
version: 4.2.0
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: anbt-sql-formatter
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - ">="
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version:
|
103
|
+
version: 0.0.7
|
104
104
|
type: :runtime
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version:
|
110
|
+
version: 0.0.7
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
112
|
name: awesome_print
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -136,12 +136,10 @@ files:
|
|
136
136
|
- LICENSE.txt
|
137
137
|
- README.md
|
138
138
|
- Rakefile
|
139
|
-
- gemfiles/rails_3_2_x.gemfile
|
140
|
-
- gemfiles/rails_4_0_x.gemfile
|
141
|
-
- gemfiles/rails_4_1_x.gemfile
|
142
139
|
- gemfiles/rails_4_2_x.gemfile
|
143
140
|
- gemfiles/rails_5_0_x.gemfile
|
144
141
|
- gemfiles/rails_5_1_x.gemfile
|
142
|
+
- gemfiles/rails_5_2_x.gemfile
|
145
143
|
- lib/flog.rb
|
146
144
|
- lib/flog/configuration.rb
|
147
145
|
- lib/flog/params_formattable.rb
|
@@ -176,7 +174,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
176
174
|
version: '0'
|
177
175
|
requirements: []
|
178
176
|
rubyforge_project:
|
179
|
-
rubygems_version: 2.6
|
177
|
+
rubygems_version: 2.7.6
|
180
178
|
signing_key:
|
181
179
|
specification_version: 4
|
182
180
|
summary: Rails log formatter for parameters and sql
|