spring_onion 1.0.1 → 1.1.0
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/Gemfile.lock +2 -2
- data/README.md +2 -1
- data/lib/spring_onion.rb +9 -1
- data/lib/spring_onion/config.rb +4 -2
- data/lib/spring_onion/explainer.rb +3 -7
- data/lib/spring_onion/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b2d9e6e733aeeb720b7b7dea0721c11b5892bc88ae8a48cdeec608028c8aae9d
|
4
|
+
data.tar.gz: d8f89788023aeb586e6df258c013a970fd28fe3c320741f41b20fd1ff5475d86
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 79e0052abddb1704f8e0f8d0d1faa4cc9ea180db04fd178917f0100c5857985ed91f219b106574409b447deb7b61efb14a3e9f8f353d15caa643edf592d6d0b0
|
7
|
+
data.tar.gz: 9bff4e63e15a9911eccc6d9f4d1614eb55c28e98d055b95f720b4653db7dbc38927c2c263ab95a1508c70f287f4ac20cb75d561a8943a64f81eb4ceb489e791b
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
spring_onion (1.0
|
4
|
+
spring_onion (1.1.0)
|
5
5
|
activerecord
|
6
6
|
coderay
|
7
7
|
mysql2
|
@@ -28,7 +28,7 @@ GEM
|
|
28
28
|
coderay (1.1.3)
|
29
29
|
concurrent-ruby (1.1.6)
|
30
30
|
diff-lcs (1.4.4)
|
31
|
-
i18n (1.8.
|
31
|
+
i18n (1.8.4)
|
32
32
|
concurrent-ruby (~> 1.0)
|
33
33
|
minitest (5.14.1)
|
34
34
|
mysql2 (0.5.3)
|
data/README.md
CHANGED
@@ -36,7 +36,8 @@ ActiveRecord::Base.establish_connection(
|
|
36
36
|
)
|
37
37
|
|
38
38
|
SpringOnion.enabled = true # or `SPRING_ONION_ENABLED=1`
|
39
|
-
|
39
|
+
# `SPRING_ONION_DATABASE_URL=mysql2://...`
|
40
|
+
# default: SpringOnion.connection = ActiveRecord::Base.connection.raw_connection
|
40
41
|
SpringOnion.source_filter_re = //
|
41
42
|
|
42
43
|
class Employee < ActiveRecord::Base; end
|
data/lib/spring_onion.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'logger'
|
4
|
-
|
4
|
+
|
5
5
|
require 'active_support'
|
6
|
+
require 'coderay'
|
7
|
+
require 'mysql2'
|
6
8
|
|
7
9
|
require 'spring_onion/config'
|
8
10
|
require 'spring_onion/error'
|
@@ -11,6 +13,12 @@ require 'spring_onion/json_logger'
|
|
11
13
|
require 'spring_onion/version'
|
12
14
|
|
13
15
|
ActiveSupport.on_load :active_record do
|
16
|
+
if ENV['SPRING_ONION_DATABASE_URL'] && !SpringOnion.connection
|
17
|
+
SpringOnion.connection = Mysql2::Client.new(
|
18
|
+
ActiveRecord::ConnectionAdapters::ConnectionSpecification::ConnectionUrlResolver.new(ENV['SPRING_ONION_DATABASE_URL']).to_hash
|
19
|
+
)
|
20
|
+
end
|
21
|
+
|
14
22
|
require 'active_record/connection_adapters/abstract_mysql_adapter'
|
15
23
|
ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter.prepend SpringOnion::Explainer
|
16
24
|
end
|
data/lib/spring_onion/config.rb
CHANGED
@@ -59,15 +59,16 @@ module SpringOnion
|
|
59
59
|
idx ? backtrace_lines.slice(idx..-1) : []
|
60
60
|
end
|
61
61
|
|
62
|
-
@logger = Logger.new($stdout).tap do |logger|
|
62
|
+
@logger = Logger.new(ENV['SPRING_ONION_LOG'] || $stdout).tap do |logger|
|
63
63
|
logger.formatter = lambda do |severity, datetime, _progname, msg|
|
64
64
|
"\n#{self}\t#{severity}\t#{datetime}\t#{msg}\n"
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
|
+
@log_all = (/\A(1|true)\z/i =~ ENV['SPRING_ONION_LOG_ALL'])
|
68
69
|
@trace_len = 3
|
69
70
|
@json_pretty = (/\A(1|true)\z/i =~ ENV['SPRING_ONION_JSON_PRETTY'])
|
70
|
-
@color = /\A(1|true)\z/i =~ ENV.fetch('SPRING_ONION_COLOR',
|
71
|
+
@color = /\A(1|true)\z/i =~ ENV.fetch('SPRING_ONION_COLOR', @logger.instance_variable_get(:@logdev)&.dev&.tty?&.to_s)
|
71
72
|
|
72
73
|
class << self
|
73
74
|
attr_accessor :enabled,
|
@@ -76,6 +77,7 @@ module SpringOnion
|
|
76
77
|
:sql_filter_re, :ignore_sql_filter_re, :sql_filter,
|
77
78
|
:source_filter_re, :ignore_source_filter_re, :source_filter,
|
78
79
|
:logger,
|
80
|
+
:log_all,
|
79
81
|
:trace_len,
|
80
82
|
:json_pretty,
|
81
83
|
:color
|
@@ -16,18 +16,14 @@ module SpringOnion
|
|
16
16
|
trace = SpringOnion.source_filter.call(caller)
|
17
17
|
|
18
18
|
unless trace.length.zero?
|
19
|
-
conn = SpringOnion.connection
|
20
|
-
raise SpringOnion::Error, 'MySQL connection is not set' unless conn
|
21
|
-
|
19
|
+
conn = SpringOnion.connection || raw_connection
|
22
20
|
exp = conn.query("EXPLAIN #{sql}", as: :hash).to_a
|
23
21
|
exp.each { |r| r.delete('id') }
|
24
22
|
_validate_explain(sql: sql, exp: exp, trace: trace)
|
25
23
|
end
|
26
24
|
end
|
27
|
-
rescue SpringOnion::Error
|
28
|
-
raise
|
29
25
|
rescue StandardError => e
|
30
|
-
SpringOnion.logger.error(e)
|
26
|
+
SpringOnion.logger.error("#{e}\n\t#{e.backtrace.join("\n\t")}")
|
31
27
|
end
|
32
28
|
|
33
29
|
yield
|
@@ -45,7 +41,7 @@ module SpringOnion
|
|
45
41
|
warning_names_by_index[i] = warning_names unless warning_names.empty?
|
46
42
|
end
|
47
43
|
|
48
|
-
return if warning_names_by_index.empty?
|
44
|
+
return if !SpringOnion.log_all && warning_names_by_index.empty?
|
49
45
|
|
50
46
|
SpringOnion::JsonLogger.log(
|
51
47
|
sql: sql,
|
data/lib/spring_onion/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spring_onion
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- winebarrel
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-07-
|
11
|
+
date: 2020-07-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|