activerecord-cause 0.2.1 → 0.3.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/.travis.yml +1 -0
- data/README.md +4 -0
- data/lib/activerecord/cause.rb +35 -24
- data/lib/activerecord/cause/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cee58644777354c3bbb13f275b2da5c322d38f15
|
4
|
+
data.tar.gz: 2c9beabd1af3167ba28e8a83b9085c6f7a568ff0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 75b3d107959a1908aab6a0cd70016ba0cc41689ef5a480ef84be64e38a4cf8a2293de3c078c1dfb42d27946cdaf335720eea162b2c44406ec9b5f2a1bc9269a2
|
7
|
+
data.tar.gz: 2180664590df42eedf60a4a5619f4fdfb98d00b60ff7d6027359ec4a683f59d828c90e7497a957c20b4efad38d233d29cf24e034c3c11a766e3163ff5242d194
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -33,7 +33,11 @@ ActiveRecord::Cause.match_paths = [
|
|
33
33
|
/spec\/spec_helper/,
|
34
34
|
] # default is []
|
35
35
|
ActiveRecord::Cause.log_with_sql = true # default is false
|
36
|
+
ActiveRecord::Cause.log_mode = :all # default is :single
|
36
37
|
```
|
38
|
+
|
39
|
+
If `log_mode` is `:all`, outputs all matched locations;
|
40
|
+
|
37
41
|
```ruby
|
38
42
|
# spec/spec_helper.rb
|
39
43
|
User.all
|
data/lib/activerecord/cause.rb
CHANGED
@@ -15,6 +15,11 @@ module ActiveRecord
|
|
15
15
|
false
|
16
16
|
end
|
17
17
|
|
18
|
+
# :single or :all
|
19
|
+
config_accessor :log_mode, instance_accessor: false do
|
20
|
+
:single
|
21
|
+
end
|
22
|
+
|
18
23
|
class LogSubscriber < ActiveRecord::LogSubscriber
|
19
24
|
IGNORE_PAYLOAD_NAMES = ["SCHEMA", "EXPLAIN"]
|
20
25
|
|
@@ -26,42 +31,48 @@ module ActiveRecord
|
|
26
31
|
|
27
32
|
return if IGNORE_PAYLOAD_NAMES.include?(payload[:name])
|
28
33
|
|
29
|
-
|
34
|
+
locations = caller_locations.select do |l|
|
30
35
|
ActiveRecord::Cause.match_paths.any? do |re|
|
31
36
|
re.match(l.absolute_path)
|
32
37
|
end
|
33
38
|
end
|
34
39
|
|
35
|
-
return
|
40
|
+
return if locations.empty?
|
36
41
|
|
37
|
-
|
38
|
-
|
39
|
-
binds = nil
|
40
|
-
|
41
|
-
if respond_to?(:render_bind)
|
42
|
-
unless (payload[:binds] || []).empty?
|
43
|
-
binds = " " + payload[:binds].map { |col,v|
|
44
|
-
render_bind(col, v)
|
45
|
-
}.inspect
|
46
|
-
end
|
42
|
+
if ActiveRecord::Cause.log_mode != :all
|
43
|
+
locations = locations.take(1)
|
47
44
|
end
|
48
45
|
|
49
|
-
|
50
|
-
name
|
51
|
-
sql
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
46
|
+
locations.each do |loc|
|
47
|
+
name = "#{payload[:name]} (ActiveRecord::Cause)"
|
48
|
+
sql = payload[:sql]
|
49
|
+
binds = nil
|
50
|
+
|
51
|
+
if respond_to?(:render_bind)
|
52
|
+
unless (payload[:binds] || []).empty?
|
53
|
+
binds = " " + payload[:binds].map { |col,v|
|
54
|
+
render_bind(col, v)
|
55
|
+
}.inspect
|
56
|
+
end
|
57
|
+
end
|
56
58
|
|
57
|
-
|
58
|
-
|
59
|
-
|
59
|
+
if odd?
|
60
|
+
name = color(name, CYAN, true)
|
61
|
+
sql = color(sql, nil, true)
|
60
62
|
else
|
61
|
-
|
63
|
+
name = color(name, MAGENTA, true)
|
62
64
|
end
|
65
|
+
cause = color(loc.to_s, nil, true)
|
63
66
|
|
64
|
-
|
67
|
+
output =
|
68
|
+
if ActiveRecord::Cause.log_with_sql
|
69
|
+
" #{name} #{sql}#{binds} caused by #{cause}"
|
70
|
+
else
|
71
|
+
" #{name} caused by #{cause}"
|
72
|
+
end
|
73
|
+
|
74
|
+
debug(output)
|
75
|
+
end
|
65
76
|
end
|
66
77
|
end
|
67
78
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-cause
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- joker1007
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-05-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|