rorvswild 1.0.0.pre.alpha → 1.0.0.pre.alpha2

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: 1736359534ad385b3f94023b6f58aedeb80758d9
4
- data.tar.gz: 7b3977b85d8cc46cf332bccd8ada6c8ed482a1a4
3
+ metadata.gz: b2e54a9c9fc7d9ef4b92bc45f8f0ecbc52105af2
4
+ data.tar.gz: 7961fe5c7ae2c6feb83cfd5c08e00d73b9cbe4f8
5
5
  SHA512:
6
- metadata.gz: 0851e785429d0263cdf0f0b98792db188a9616fc16bb98847dd2e1ccb979e3627a5a591f6282468c62e18ca46ccba79aaa10441c60f2b258d51b174d28c25489
7
- data.tar.gz: 02e3b948d90d5fb378c6707d6e2d563348a1549bec9465e7a5dd2d00488d918d229e9d5ef0ef11dc3cf4453ea8d686539b8ff6c1e6695ae5ef768ab1e8b021b3
6
+ metadata.gz: 4a38e82f8384ce51edc22282b536047f1f38a3c33cc4e465bbfdf22e81720e928fbce9e8eda575a5e3e8906faa9c113afde036d4955cda6ee3e6b7cf5bdf9989
7
+ data.tar.gz: bf0b0b27b2e44bd742b6374b351f5736d2cdbc8742346d218cfbd9ecc9da314271c32f69b6a4aeb30efd5bcc5be8e4d185b6871a291c3dc3c1009ac0ab1d8046
@@ -161,9 +161,8 @@ module RorVsWild
161
161
  end
162
162
 
163
163
  def exception_to_hash(exception, extra_details = nil)
164
- file, line, method = extract_most_relevant_file_and_line(exception.backtrace_locations)
164
+ file, line = extract_most_relevant_file_and_line_from_exception(exception)
165
165
  {
166
- method: method,
167
166
  line: line.to_i,
168
167
  file: relative_path(file),
169
168
  message: exception.message,
@@ -1,13 +1,29 @@
1
1
  module RorVsWild
2
2
  module Location
3
+ def extract_most_relevant_file_and_line(locations)
4
+ location = find_most_relevant_location(locations)
5
+ [relative_path(location.path), location.lineno]
6
+ end
7
+
3
8
  def find_most_relevant_location(locations)
4
9
  result = locations.find { |l| l.path.index(app_root) == 0 && !(l.path =~ gem_home_regex) } if app_root
5
10
  result || locations.find { |l| !(l.path =~ gem_home_regex) } || locations.first
6
11
  end
7
12
 
8
- def extract_most_relevant_file_and_line(stack)
9
- location = find_most_relevant_location(stack)
10
- [relative_path(location.path), location.lineno]
13
+ def extract_most_relevant_file_and_line_from_exception(exception)
14
+ # Exception#backtrace_locations is faster but exists since 2.1.0.
15
+ # Sometime Exception#backtrace_locations returns nil for an unknow reason. So we fallback to the old way.
16
+ if exception.respond_to?(:backtrace_locations) && locations = exception.backtrace_locations
17
+ extract_most_relevant_file_and_line(locations)
18
+ else
19
+ extract_most_relevant_file_and_line_from_array_of_strings(exception.backtrace)
20
+ end
21
+ end
22
+
23
+ def extract_most_relevant_file_and_line_from_array_of_strings(stack)
24
+ location = stack.find { |str| str =~ app_root_regex && !(str =~ gem_home_regex) } if app_root_regex
25
+ location ||= stack.find { |str| !(str =~ gem_home_regex) } if gem_home_regex
26
+ relative_path(location || stack.first).split(":".freeze)
11
27
  end
12
28
 
13
29
  def gem_home_regex
@@ -1,3 +1,3 @@
1
1
  module RorVsWild
2
- VERSION = "1.0.0-alpha".freeze
2
+ VERSION = "1.0.0-alpha2".freeze
3
3
  end
@@ -126,6 +126,14 @@ class RorVsWildTest < Minitest::Test
126
126
  ENV["GEM_HOME"], ENV["GEM_PATH"] = original_gem_home, original_gem_path
127
127
  end
128
128
 
129
+ def test_extract_most_relevant_file_and_line_from_array_of_strings
130
+ callstack = ["#{ENV["GEM_HOME"]}/lib/sql.rb:1", "/usr/lib/ruby/net/http.rb:2", "/rails/root/app/models/user.rb:3"]
131
+ assert_equal(["/app/models/user.rb", "3"], agent.extract_most_relevant_file_and_line_from_array_of_strings(callstack))
132
+
133
+ locations = ["#{ENV["GEM_HOME"]}/lib/sql.rb:1"]
134
+ assert_equal(["#{ENV["GEM_HOME"]}/lib/sql.rb", "1"], agent.extract_most_relevant_file_and_line_from_array_of_strings(locations))
135
+ end
136
+
129
137
  private
130
138
 
131
139
  def agent
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: 1.0.0.pre.alpha
4
+ version: 1.0.0.pre.alpha2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexis Bernard
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-18 00:00:00.000000000 Z
11
+ date: 2017-04-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler