Class: Salopulse::StackFrameBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/salopulse/stack_frame_builder.rb

Constant Summary collapse

BACKTRACE_LINE =
/\A(?<file>.+?):(?<line>\d+):in\s+[`'](?<method>.+?)['`]\z/
CONTEXT_LINES =
5
MAX_FRAMES =
50
FRAMEWORK_MARKERS =
[ "/gems/", "/rubygems/", "/bundle/" ].freeze
SOURCE_CACHE =
{}
SOURCE_CACHE_MUTEX =
Mutex.new
SOURCE_CACHE_LIMIT =
512

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(backtrace, app_root:) ⇒ StackFrameBuilder

Returns a new instance of StackFrameBuilder.



16
17
18
19
# File 'lib/salopulse/stack_frame_builder.rb', line 16

def initialize(backtrace, app_root:)
  @backtrace = Array(backtrace)
  @app_root = app_root && File.expand_path(app_root.to_s)
end

Class Method Details

.call(backtrace, app_root: nil) ⇒ Object



12
13
14
# File 'lib/salopulse/stack_frame_builder.rb', line 12

def self.call(backtrace, app_root: nil)
  new(backtrace, app_root: app_root).call
end

Instance Method Details

#callObject



21
22
23
24
# File 'lib/salopulse/stack_frame_builder.rb', line 21

def call
  frames = @backtrace.first(MAX_FRAMES).filter_map { |line| build_frame(line.to_s) }
  dedupe_consecutive(frames)
end