class Opbeat::ErrorMessage::Stacktrace::Frame

Constants

BACKTRACE_REGEX

Public Class Methods

from_line(config, line) click to toggle source
# File lib/opbeat/error_message/stacktrace.rb, line 31
def from_line config, line
  _, abs_path, lineno, function = line.match(BACKTRACE_REGEX).to_a
  lineno = lineno.to_i
  filename = strip_load_path(abs_path)

  if lines = config.context_lines
    pre_context, context_line, post_context =
      get_contextlines(abs_path, lineno, lines)
  end

  new filename, lineno, abs_path, function, nil,
    pre_context, context_line, post_context
end

Private Class Methods

get_contextlines(path, line, context) click to toggle source
# File lib/opbeat/error_message/stacktrace.rb, line 59
def get_contextlines path, line, context
  lines = (2 * context + 1).times.map do |i|
    LineCache.find(path, line - context + i)
  end

  pre =  lines[0..(context-1)]
  line = lines[context]
  post = lines[(context+1)..-1]

  [pre, line, post]
end
strip_load_path(path) click to toggle source
# File lib/opbeat/error_message/stacktrace.rb, line 47
def strip_load_path path
  prefix = $:
    .map(&:to_s)
    .select { |s| path.start_with?(s) }
    .sort_by { |s| s.length }
    .last

  return path unless prefix

  path[prefix.chomp(File::SEPARATOR).length + 1..-1]
end