class Sentry::StacktraceInterface::Frame

Not actually an interface, but I want to use the same style

Attributes

abs_path[RW]
context_line[RW]
filename[RW]
function[RW]
in_app[RW]
lineno[RW]
module[RW]
post_context[RW]
pre_context[RW]
vars[RW]

Public Class Methods

new(project_root, line) click to toggle source
# File lib/sentry/interfaces/stacktrace.rb, line 20
def initialize(project_root, line)
  @project_root = project_root

  @abs_path = line.file
  @function = line.method if line.method
  @lineno = line.number
  @in_app = line.in_app
  @module = line.module_name if line.module_name
  @filename = compute_filename
end

Public Instance Methods

compute_filename() click to toggle source
# File lib/sentry/interfaces/stacktrace.rb, line 31
def compute_filename
  return if abs_path.nil?

  prefix =
    if under_project_root? && in_app
      @project_root
    elsif under_project_root?
      longest_load_path || @project_root
    else
      longest_load_path
    end

  prefix ? abs_path[prefix.to_s.chomp(File::SEPARATOR).length + 1..-1] : abs_path
end
set_context(linecache, context_lines) click to toggle source
# File lib/sentry/interfaces/stacktrace.rb, line 46
def set_context(linecache, context_lines)
  return unless abs_path

  @pre_context, @context_line, @post_context = \
      linecache.get_file_context(abs_path, lineno, context_lines)
end
to_hash(*args) click to toggle source
Calls superclass method Sentry::Interface#to_hash
# File lib/sentry/interfaces/stacktrace.rb, line 53
def to_hash(*args)
  data = super(*args)
  data.delete(:vars) unless vars && !vars.empty?
  data.delete(:pre_context) unless pre_context && !pre_context.empty?
  data.delete(:post_context) unless post_context && !post_context.empty?
  data.delete(:context_line) unless context_line && !context_line.empty?
  data
end

Private Instance Methods

longest_load_path() click to toggle source
# File lib/sentry/interfaces/stacktrace.rb, line 68
def longest_load_path
  $LOAD_PATH.select { |path| abs_path.start_with?(path.to_s) }.max_by(&:size)
end
under_project_root?() click to toggle source
# File lib/sentry/interfaces/stacktrace.rb, line 64
def under_project_root?
  @project_root && abs_path.start_with?(@project_root)
end