rorvswild 0.1.2 → 0.1.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9692fc304ba53c4419979e2e90f80c8dddcbe52c
4
- data.tar.gz: 6c604d217cda610c5f2c3e0cee95cbb09ff9aac1
3
+ metadata.gz: eeecdd2dfd26ee6068a96bcb067e946e8bd1b904
4
+ data.tar.gz: 39387cead4fa49a5c6ee04ce03a35950ed1ff5c0
5
5
  SHA512:
6
- metadata.gz: 9925488161d75f9d0a01893abf87c4486b958e468379fd198cc973dc7ff50af27977c6c8b0167194befc6076c623fa5f2ae80042e01d652881c5634607ce2d35
7
- data.tar.gz: b98e6ec554834ce2b6449037fea17732a3413442ee7fd0e811ba1b61ddd936ebe47e3fc916809855e684ecf73879a87d349f4348646b71e4b9830d21e5de0b23
6
+ metadata.gz: 1d142fb4e7f10a32220e44e12665b1ad311a250790274c65e3cf4c11d4aa2390e480aca3e6dabfc4b2345986b4faa1445d9c3a3542024ba039834f03a3a22842
7
+ data.tar.gz: ead8f7d8516a43c70c2625868752938188cdfce6a9dd522ea6f339bdac66bb3dbed450eaff216eb42fce732dac633feb24690f1b1f2f8fef629493f415527ca0
@@ -1,3 +1,3 @@
1
1
  module RorVsWild
2
- VERSION = "0.1.2".freeze
2
+ VERSION = "0.1.3".freeze
3
3
  end
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 = extract_file_and_line_from_call_stack(caller)
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 extract_file_and_line_from_call_stack(stack)
231
- return unless location = stack.find { |str| str.include?(Rails.root.to_s) }
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.first.split(":")
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,
@@ -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("foo")
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.2
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-02-12 00:00:00.000000000 Z
11
+ date: 2015-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler