Class: Telebugs::Middleware::RootDirectoryFilter

Inherits:
BaseMiddleware show all
Defined in:
lib/telebugs/middleware/root_directory_filter.rb

Overview

Filters out the root directory from the backtrace paths.

Constant Summary

Constants inherited from BaseMiddleware

BaseMiddleware::DEFAULT_WEIGHT

Instance Method Summary collapse

Constructor Details

#initialize(root_directory) ⇒ RootDirectoryFilter

Returns a new instance of RootDirectoryFilter.



7
8
9
# File 'lib/telebugs/middleware/root_directory_filter.rb', line 7

def initialize(root_directory)
  @root_directory = root_directory
end

Instance Method Details

#call(report) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/telebugs/middleware/root_directory_filter.rb', line 11

def call(report)
  report.data[:errors].each do |error|
    error[:backtrace].each do |frame|
      next unless (file = frame[:file])
      next unless file.start_with?(@root_directory)

      frame[:root_dir] = true
      file.sub!(/#{@root_directory}\/?/, "")
    end
  end
end

#weightObject



23
24
25
# File 'lib/telebugs/middleware/root_directory_filter.rb', line 23

def weight
  -999
end