telebugs 0.4.0 → 0.5.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
  SHA256:
3
- metadata.gz: d5da4c3b22bc49e8e3e6ed286fe61c0122fa763949c04941ce87980e9876efda
4
- data.tar.gz: 2a24565987b4f25f6219a4dba913ec501555e65cd68a8fb62ec0c4fe4af5ec80
3
+ metadata.gz: c16a99db8da62fc1f475458e2af48e686917a3591389e658fc98c717c2d8b72b
4
+ data.tar.gz: 862256bda596b7c3bb3e3b02dd1477137d225eedd3fad1fd3c0cc77d574a309b
5
5
  SHA512:
6
- metadata.gz: 50c12ee34337f5375c63e50c6f624d919c7b747cebd3b3ce020254dbce7cc8f0d80fc721e49c96a282badfcd3dd8068d8ca601aa546b0a79e14e2303252b120d
7
- data.tar.gz: 9f792b211b679df2db87a6e02afcad58a348d7349acc35612748696e1f03f2f5db451253db0e24bcf1a66e7e48c7b939018addc093d0b84f2a2835d969c4aa8e
6
+ metadata.gz: a0ae8dbc6726ee21a94e8f486d992a0c1850d754e7a2c1cf7ffc662976d4bcb68209d1fc67740fcb3769d331b48e3b4bee4704cecbf84b7a0324c727c81917a9
7
+ data.tar.gz: 86768ba7aabaf96cad7daeae5d2b3d00a83159e70fc576e539058ca8cca16d91e7e20353455d17a92717ee25b041932c54ae8523c6ae42af8f7e0d35d7f1fb46
@@ -5,10 +5,10 @@ module Telebugs
5
5
  ERROR_API_URL = "https://api.telebugs.com/2024-03-28/errors"
6
6
 
7
7
  attr_accessor :api_key,
8
- :root_directory,
9
8
  :middleware
10
9
 
11
- attr_reader :api_url
10
+ attr_reader :api_url,
11
+ :root_directory
12
12
 
13
13
  class << self
14
14
  attr_writer :instance
@@ -26,6 +26,15 @@ module Telebugs
26
26
  @api_url = URI(url)
27
27
  end
28
28
 
29
+ def root_directory=(directory)
30
+ @root_directory = File.realpath(directory)
31
+
32
+ if @middleware
33
+ @middleware.delete(Middleware::RootDirectoryFilter)
34
+ @middleware.use Middleware::RootDirectoryFilter.new(@root_directory)
35
+ end
36
+ end
37
+
29
38
  def reset
30
39
  self.api_key = nil
31
40
  self.api_url = ERROR_API_URL
@@ -35,6 +44,8 @@ module Telebugs
35
44
  )
36
45
 
37
46
  @middleware = MiddlewareStack.new
47
+ @middleware.use Middleware::GemRootFilter.new
48
+ @middleware.use Middleware::RootDirectoryFilter.new(root_directory)
38
49
  end
39
50
  end
40
51
  end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Telebugs
4
+ class Middleware
5
+ # GemRootFilter is a middleware that filters out the root path of the gems.
6
+ # It replaces the root path with the gem name and version.
7
+ class GemRootFilter < Telebugs::Middleware
8
+ def initialize
9
+ @gem_paths = Gem.path.map { |path| /\A#{Regexp.escape(path)}\/gems\// }
10
+ end
11
+
12
+ def call(report)
13
+ report.data[:errors].each do |error|
14
+ process_backtrace(error[:backtrace])
15
+ end
16
+ end
17
+
18
+ def weight
19
+ -999
20
+ end
21
+
22
+ private
23
+
24
+ def process_backtrace(backtrace)
25
+ backtrace.each do |frame|
26
+ next unless (file = frame[:file])
27
+
28
+ process_frame(frame, file)
29
+ end
30
+ end
31
+
32
+ def process_frame(frame, file)
33
+ @gem_paths.each do |gem_path_regex|
34
+ next unless file&.match?(gem_path_regex)
35
+
36
+ frame[:file] = format_file(file.sub(gem_path_regex, ""))
37
+ break
38
+ end
39
+ end
40
+
41
+ def format_file(file)
42
+ parts = file.split("/")
43
+
44
+ gem_info = parts[0].split("-")
45
+ gem_name = gem_info[0]
46
+ gem_version = gem_info[1]
47
+
48
+ file_path = parts[1..].join("/")
49
+
50
+ "#{gem_name} (#{gem_version}) #{file_path}"
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Telebugs
4
+ class Middleware
5
+ # Filters out the root directory from the backtrace paths.
6
+ class RootDirectoryFilter < Telebugs::Middleware
7
+ def initialize(root_directory)
8
+ @root_directory = root_directory
9
+ end
10
+
11
+ def call(report)
12
+ report.data[:errors].each do |error|
13
+ error[:backtrace].each do |frame|
14
+ next unless (file = frame[:file])
15
+ next unless file.start_with?(@root_directory)
16
+
17
+ file.sub!(/#{@root_directory}\/?/, "")
18
+ end
19
+ end
20
+ end
21
+
22
+ def weight
23
+ -999
24
+ end
25
+ end
26
+ end
27
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Telebugs
4
- VERSION = "0.4.0"
4
+ VERSION = "0.5.0"
5
5
  end
data/lib/telebugs.rb CHANGED
@@ -19,6 +19,9 @@ require_relative "telebugs/middleware"
19
19
  require_relative "telebugs/middleware_stack"
20
20
  require_relative "telebugs/truncator"
21
21
 
22
+ require_relative "telebugs/middleware/gem_root_filter"
23
+ require_relative "telebugs/middleware/root_directory_filter"
24
+
22
25
  module Telebugs
23
26
  # The general error that this library uses when it wants to raise.
24
27
  Error = Class.new(StandardError)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: telebugs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kyrylo Silin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-06-17 00:00:00.000000000 Z
11
+ date: 2024-06-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -58,6 +58,8 @@ files:
58
58
  - lib/telebugs/error_message.rb
59
59
  - lib/telebugs/file_cache.rb
60
60
  - lib/telebugs/middleware.rb
61
+ - lib/telebugs/middleware/gem_root_filter.rb
62
+ - lib/telebugs/middleware/root_directory_filter.rb
61
63
  - lib/telebugs/middleware_stack.rb
62
64
  - lib/telebugs/promise.rb
63
65
  - lib/telebugs/report.rb