class InfluxReporter::ErrorMessage::Stacktrace::Frame

Constants

BACKTRACE_REGEX

Public Class Methods

from_line(config, line) click to toggle source
# File lib/influx_reporter/error_message/stacktrace.rb, line 33
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/influx_reporter/error_message/stacktrace.rb, line 61
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/influx_reporter/error_message/stacktrace.rb, line 49
def strip_load_path(path)
  prefix = $LOAD_PATH
               .map(&:to_s)
               .select { |s| path.start_with?(s) }
               .sort_by(&:length)
               .last

  return path unless prefix

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