activerecord-cause 0.3.0 → 0.4.0.beta

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: cee58644777354c3bbb13f275b2da5c322d38f15
4
- data.tar.gz: 2c9beabd1af3167ba28e8a83b9085c6f7a568ff0
3
+ metadata.gz: f896ab758049167f03bc26eb7e1acecfc584c516
4
+ data.tar.gz: e27e4af7d2f5f54f38d0ed74f1f4e9d71258c4cc
5
5
  SHA512:
6
- metadata.gz: 75b3d107959a1908aab6a0cd70016ba0cc41689ef5a480ef84be64e38a4cf8a2293de3c078c1dfb42d27946cdaf335720eea162b2c44406ec9b5f2a1bc9269a2
7
- data.tar.gz: 2180664590df42eedf60a4a5619f4fdfb98d00b60ff7d6027359ec4a683f59d828c90e7497a957c20b4efad38d233d29cf24e034c3c11a766e3163ff5242d194
6
+ metadata.gz: 6b367c82a2f025d83e711259e61073049f5f8708b7c1d8a851ec25e3c511f746e4d0e70aab8a22d9a7493287c7e83f176c0daa7bd7759425bdf260c2a523dbe6
7
+ data.tar.gz: 9fe25f5e71f87938501747d56d3edf292e58f78ac1226b504259c49cbba4b7f2de53b7d1efd7ae80228c364a7c5cada28d9271ac4b17b3daee40338bf898203a
data/.travis.yml CHANGED
@@ -1,10 +1,10 @@
1
1
  language: ruby
2
2
  sudo: false
3
3
  rvm:
4
- - 2.2.1
5
- - 2.1
4
+ - 2.3.0
5
+ - 2.2.4
6
6
  gemfile:
7
- - gemfiles/activerecord-32.gemfile
8
7
  - gemfiles/activerecord-40.gemfile
9
8
  - gemfiles/activerecord-41.gemfile
10
9
  - gemfiles/activerecord-42.gemfile
10
+ - gemfiles/activerecord-50.gemfile
data/Rakefile CHANGED
@@ -7,19 +7,41 @@ task :default => :spec
7
7
 
8
8
  pwd = File.expand_path('../', __FILE__)
9
9
 
10
+ gemfiles = %w(activerecord-40 activerecord-41 activerecord-42 activerecord-50)
11
+
10
12
  namespace :spec do
11
- %w(activerecord-32 activerecord-40 activerecord-41 activerecord-42).each do |gemfile|
13
+ gemfiles.each do |gemfile|
12
14
  desc "Run Tests by #{gemfile}.gemfile"
13
15
  task gemfile do
14
- sh "BUNDLE_GEMFILE='#{pwd}/gemfiles/#{gemfile}.gemfile' bundle install --path #{pwd}/.bundle"
15
- sh "BUNDLE_GEMFILE='#{pwd}/gemfiles/#{gemfile}.gemfile' bundle exec rake -t spec"
16
+ Bundler.with_clean_env do
17
+ sh "BUNDLE_GEMFILE='#{pwd}/gemfiles/#{gemfile}.gemfile' bundle install --path #{pwd}/.bundle"
18
+ sh "BUNDLE_GEMFILE='#{pwd}/gemfiles/#{gemfile}.gemfile' bundle exec rake -t spec"
19
+ end
16
20
  end
17
21
  end
18
22
 
19
23
  desc "Run All Tests"
20
24
  task :all do
21
- %w(activerecord-32 activerecord-40 activerecord-41 activerecord-42).each do |gemfile|
25
+ gemfiles.each do |gemfile|
22
26
  Rake::Task["spec:#{gemfile}"].invoke
23
27
  end
24
28
  end
25
29
  end
30
+
31
+ namespace :bundle_update do
32
+ gemfiles.each do |gemfile|
33
+ desc "Run Tests by #{gemfile}.gemfile"
34
+ task gemfile do
35
+ Bundler.with_clean_env do
36
+ sh "BUNDLE_GEMFILE='#{pwd}/gemfiles/#{gemfile}.gemfile' bundle update"
37
+ end
38
+ end
39
+ end
40
+
41
+ desc "Run All Tests"
42
+ task :all do
43
+ gemfiles.each do |gemfile|
44
+ Rake::Task["bundle_update:#{gemfile}"].invoke
45
+ end
46
+ end
47
+ end
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_runtime_dependency "activerecord", ">= 3.2"
21
+ spec.add_runtime_dependency "activerecord", ">= 4"
22
22
 
23
23
  spec.add_development_dependency "bundler", ">= 1.6"
24
24
  spec.add_development_dependency "rake", "~> 10.0"
@@ -1,5 +1,5 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- gem "activerecord", "~> 4.1.0"
3
+ gem "activerecord", "~> 4.2.0"
4
4
 
5
5
  gemspec :path => "../"
@@ -1,5 +1,5 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- gem "activerecord", "~> 3.2.0"
3
+ gem "activerecord", "~> 5.0.0.beta"
4
4
 
5
5
  gemspec :path => "../"
@@ -24,13 +24,23 @@ module ActiveRecord
24
24
  IGNORE_PAYLOAD_NAMES = ["SCHEMA", "EXPLAIN"]
25
25
 
26
26
  def sql(event)
27
- return if ActiveRecord::Cause.match_paths.empty?
28
27
  return unless logger.debug?
29
28
 
30
29
  payload = event.payload
31
30
 
32
31
  return if IGNORE_PAYLOAD_NAMES.include?(payload[:name])
33
32
 
33
+ if ActiveRecord.version >= Gem::Version.new("5.0.0.beta")
34
+ sql_for_ar5(event)
35
+ else
36
+ sql_for_ar4(event)
37
+ end
38
+ end
39
+
40
+ private
41
+
42
+ def sql_for_ar4(event)
43
+ payload = event.payload
34
44
  locations = caller_locations.select do |l|
35
45
  ActiveRecord::Cause.match_paths.any? do |re|
36
46
  re.match(l.absolute_path)
@@ -48,12 +58,10 @@ module ActiveRecord
48
58
  sql = payload[:sql]
49
59
  binds = nil
50
60
 
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
61
+ unless (payload[:binds] || []).empty?
62
+ binds = " " + payload[:binds].map { |col,v|
63
+ render_bind(col, v)
64
+ }.inspect
57
65
  end
58
66
 
59
67
  if odd?
@@ -74,6 +82,48 @@ module ActiveRecord
74
82
  debug(output)
75
83
  end
76
84
  end
85
+
86
+ def sql_for_ar5(event)
87
+ payload = event.payload
88
+ locations = get_locations
89
+ return if locations.empty?
90
+
91
+ if ActiveRecord::Cause.log_mode != :all
92
+ locations = locations.take(1)
93
+ end
94
+
95
+ locations.each do |loc|
96
+ name = "#{payload[:name]} (ActiveRecord::Cause)"
97
+ sql = payload[:sql]
98
+ binds = nil
99
+
100
+ unless (payload[:binds] || []).empty?
101
+ binds = " " + payload[:binds].map { |attr| render_bind(attr) }.inspect
102
+ end
103
+
104
+ name = colorize_payload_name(name, payload[:name])
105
+ sql = color(sql, sql_color(sql), true)
106
+ cause = color(loc.to_s, nil, true)
107
+
108
+ output =
109
+ if ActiveRecord::Cause.log_with_sql
110
+ " #{name} #{sql}#{binds} caused by #{cause}"
111
+ else
112
+ " #{name} caused by #{cause}"
113
+ end
114
+
115
+ debug(output)
116
+ end
117
+ end
118
+
119
+ def get_locations
120
+ return [] if ActiveRecord::Cause.match_paths.empty?
121
+ caller_locations.select do |l|
122
+ ActiveRecord::Cause.match_paths.any? do |re|
123
+ re.match(l.absolute_path)
124
+ end
125
+ end
126
+ end
77
127
  end
78
128
  end
79
129
  end
@@ -1,5 +1,5 @@
1
1
  module ActiveRecord
2
2
  module Cause
3
- VERSION = "0.3.0"
3
+ VERSION = "0.4.0.beta"
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.3.0
4
+ version: 0.4.0.beta
5
5
  platform: ruby
6
6
  authors:
7
7
  - joker1007
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-05-26 00:00:00.000000000 Z
11
+ date: 2016-04-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '3.2'
19
+ version: '4'
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: '3.2'
26
+ version: '4'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -96,10 +96,10 @@ files:
96
96
  - activerecord-cause.gemspec
97
97
  - bin/console
98
98
  - bin/setup
99
- - gemfiles/activerecord-32.gemfile
100
99
  - gemfiles/activerecord-40.gemfile
101
100
  - gemfiles/activerecord-41.gemfile
102
101
  - gemfiles/activerecord-42.gemfile
102
+ - gemfiles/activerecord-50.gemfile
103
103
  - lib/activerecord/cause.rb
104
104
  - lib/activerecord/cause/railtie.rb
105
105
  - lib/activerecord/cause/version.rb
@@ -117,12 +117,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
117
117
  version: '0'
118
118
  required_rubygems_version: !ruby/object:Gem::Requirement
119
119
  requirements:
120
- - - ">="
120
+ - - ">"
121
121
  - !ruby/object:Gem::Version
122
- version: '0'
122
+ version: 1.3.1
123
123
  requirements: []
124
124
  rubyforge_project:
125
- rubygems_version: 2.4.6
125
+ rubygems_version: 2.5.1
126
126
  signing_key:
127
127
  specification_version: 4
128
128
  summary: This gem logs where ActiveRecord actually loads record