rorvswild 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rorvswild/version.rb +1 -1
- data/lib/rorvswild.rb +14 -5
- data/test/ror_vs_wild_test.rb +15 -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: eeecdd2dfd26ee6068a96bcb067e946e8bd1b904
|
4
|
+
data.tar.gz: 39387cead4fa49a5c6ee04ce03a35950ed1ff5c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d142fb4e7f10a32220e44e12665b1ad311a250790274c65e3cf4c11d4aa2390e480aca3e6dabfc4b2345986b4faa1445d9c3a3542024ba039834f03a3a22842
|
7
|
+
data.tar.gz: ead8f7d8516a43c70c2625868752938188cdfce6a9dd522ea6f339bdac66bb3dbed450eaff216eb42fce732dac633feb24690f1b1f2f8fef629493f415527ca0
|
data/lib/rorvswild/version.rb
CHANGED
data/lib/rorvswild.rb
CHANGED
@@ -88,7 +88,7 @@ module RorVsWild
|
|
88
88
|
def after_sql_query(name, start, finish, id, payload)
|
89
89
|
return if !queries || payload[:name] == "EXPLAIN".freeze
|
90
90
|
runtime, sql, plan = compute_duration(start, finish), nil, nil
|
91
|
-
file, line, method =
|
91
|
+
file, line, method = extract_query_location(caller)
|
92
92
|
# I can't figure out the exact location which triggered the query, so at least the SQL is logged.
|
93
93
|
sql, file, line, method = payload[:sql], "Unknow", 0, "Unknow" if !file
|
94
94
|
sql = payload[:sql] if runtime >= log_sql_threshold
|
@@ -227,11 +227,19 @@ module RorVsWild
|
|
227
227
|
post("/errors", error: hash)
|
228
228
|
end
|
229
229
|
|
230
|
-
def
|
231
|
-
|
230
|
+
def extract_query_location(stack)
|
231
|
+
if location = stack.find { |str| str.include?(Rails.root.to_s) }
|
232
|
+
split_file_location(location.sub(Rails.root.to_s, "".freeze))
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
def extract_error_location(stack)
|
237
|
+
extract_query_location(stack) || split_file_location(stack.first)
|
238
|
+
end
|
239
|
+
|
240
|
+
def split_file_location(location)
|
232
241
|
file, line, method = location.split(":")
|
233
242
|
method = cleanup_method_name(method)
|
234
|
-
file.sub!(Rails.root.to_s, "")
|
235
243
|
[file, line, method]
|
236
244
|
end
|
237
245
|
|
@@ -251,8 +259,9 @@ module RorVsWild
|
|
251
259
|
end
|
252
260
|
|
253
261
|
def exception_to_hash(exception, extra_details = nil)
|
254
|
-
file, line = exception.backtrace
|
262
|
+
file, line, method = extract_error_location(exception.backtrace)
|
255
263
|
{
|
264
|
+
method: method,
|
256
265
|
line: line.to_i,
|
257
266
|
file: relative_path(file),
|
258
267
|
message: exception.message,
|
data/test/ror_vs_wild_test.rb
CHANGED
@@ -56,6 +56,20 @@ class RorVsWildTest < MiniTest::Unit::TestCase
|
|
56
56
|
assert_equal(2, RorVsWild.catch_error { 1 + 1 })
|
57
57
|
end
|
58
58
|
|
59
|
+
def test_extract_query_location
|
60
|
+
callstack = ["/ruby/gems/lib/sql.rb:1:in `method1'", "#{Rails.root}/app/models/user.rb:2:in `method2'"]
|
61
|
+
assert_equal(%w[/app/models/user.rb 2 method2], client.send(:extract_query_location, callstack))
|
62
|
+
refute(client.send(:extract_query_location, ["/ruby/gems/lib/sql.rb:1:in `method1'", "/foo/bar.rb:2:in `method2'"]))
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_extract_error_location
|
66
|
+
callstack = ["/ruby/gems/lib/sql.rb:1:in `method1'", "#{Rails.root}/app/models/user.rb:2:in `method2'"]
|
67
|
+
assert_equal(%w[/app/models/user.rb 2 method2], client.send(:extract_error_location, callstack))
|
68
|
+
|
69
|
+
callstack = ["/ruby/gems/lib/sql.rb:1:in `method1'", "/foo/bar.rb:2:in `method2'"]
|
70
|
+
assert_equal(%w[/ruby/gems/lib/sql.rb 1 method1], client.send(:extract_error_location, callstack))
|
71
|
+
end
|
72
|
+
|
59
73
|
private
|
60
74
|
|
61
75
|
def client
|
@@ -75,6 +89,6 @@ require "pathname"
|
|
75
89
|
|
76
90
|
module Rails
|
77
91
|
def self.root
|
78
|
-
Pathname.new("
|
92
|
+
Pathname.new("/rails/root")
|
79
93
|
end
|
80
94
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rorvswild
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexis Bernard
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|