activerecord-cause 0.2.1 → 0.3.0

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: caf49982c78598ccf4fa30e66695e8c0c1d54167
4
- data.tar.gz: 8ad409078427198c9e13f2075d86a8c7baa8c48b
3
+ metadata.gz: cee58644777354c3bbb13f275b2da5c322d38f15
4
+ data.tar.gz: 2c9beabd1af3167ba28e8a83b9085c6f7a568ff0
5
5
  SHA512:
6
- metadata.gz: cfa3950a883bb016cc2940efca340e3010775b5384060f5887bbc8cb4ee7d2f727bcd63ca4dfc47128a429dbcbf341ea2ba6f8af073ea72832d5f711a8169abb
7
- data.tar.gz: ebf8f857ac336cbd227a7863ba50a3fe731247085dc111386bbceb26fb0da6e8de37f935e531152e24857a6c18e4b01bf815c0bd862979616150bd5bec6a7f31
6
+ metadata.gz: 75b3d107959a1908aab6a0cd70016ba0cc41689ef5a480ef84be64e38a4cf8a2293de3c078c1dfb42d27946cdaf335720eea162b2c44406ec9b5f2a1bc9269a2
7
+ data.tar.gz: 2180664590df42eedf60a4a5619f4fdfb98d00b60ff7d6027359ec4a683f59d828c90e7497a957c20b4efad38d233d29cf24e034c3c11a766e3163ff5242d194
data/.travis.yml CHANGED
@@ -7,3 +7,4 @@ gemfile:
7
7
  - gemfiles/activerecord-32.gemfile
8
8
  - gemfiles/activerecord-40.gemfile
9
9
  - gemfiles/activerecord-41.gemfile
10
+ - gemfiles/activerecord-42.gemfile
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
@@ -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
- loc = caller_locations.find do |l|
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 unless loc
40
+ return if locations.empty?
36
41
 
37
- name = "#{payload[:name]} (ActiveRecord::Cause)"
38
- sql = payload[:sql]
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
- if odd?
50
- name = color(name, CYAN, true)
51
- sql = color(sql, nil, true)
52
- else
53
- name = color(name, MAGENTA, true)
54
- end
55
- cause = color(loc.to_s, nil, true)
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
- output =
58
- if ActiveRecord::Cause.log_with_sql
59
- " #{name} #{sql}#{binds} caused by #{cause}"
59
+ if odd?
60
+ name = color(name, CYAN, true)
61
+ sql = color(sql, nil, true)
60
62
  else
61
- " #{name} caused by #{cause}"
63
+ name = color(name, MAGENTA, true)
62
64
  end
65
+ cause = color(loc.to_s, nil, true)
63
66
 
64
- debug(output)
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
@@ -1,5 +1,5 @@
1
1
  module ActiveRecord
2
2
  module Cause
3
- VERSION = "0.2.1"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  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.2.1
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-04-16 00:00:00.000000000 Z
11
+ date: 2015-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord