Sha256: a796c3060239ba9e9ab7a61700625d753cf1cdda507f7d20cb893772d982e6bc

Contents?: true

Size: 1.58 KB

Versions: 10

Compression:

Stored size: 1.58 KB

Contents

module Sentry
  class StacktraceInterface < Interface
    attr_accessor :frames

    def to_hash
      data = super
      data[:frames] = data[:frames].map(&:to_hash)
      data
    end

    # Not actually an interface, but I want to use the same style
    class Frame < Interface
      attr_accessor :abs_path, :context_line, :function, :in_app,
                    :lineno, :module, :pre_context, :post_context, :vars

      def initialize(project_root)
        @project_root = project_root
      end

      def filename
        return if abs_path.nil?
        return @filename if instance_variable_defined?(:@filename)

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

        @filename = prefix ? abs_path[prefix.to_s.chomp(File::SEPARATOR).length + 1..-1] : abs_path
      end

      def to_hash(*args)
        data = super(*args)
        data[:filename] = filename
        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

      def under_project_root?
        @project_root && abs_path.start_with?(@project_root)
      end

      def longest_load_path
        $LOAD_PATH.select { |path| abs_path.start_with?(path.to_s) }.max_by(&:size)
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
sentry-ruby-4.1.2 lib/sentry/interfaces/stacktrace.rb
sentry-ruby-4.1.1 lib/sentry/interfaces/stacktrace.rb
sentry-ruby-4.1.0 lib/sentry/interfaces/stacktrace.rb
sentry-ruby-4.0.1 lib/sentry/interfaces/stacktrace.rb
sentry-ruby-4.0.0 lib/sentry/interfaces/stacktrace.rb
sentry-ruby-0.3.0 lib/sentry/interfaces/stacktrace.rb
sentry-ruby-0.2.0 lib/sentry/interfaces/stacktrace.rb
sentry-ruby-0.1.3 lib/sentry/interfaces/stacktrace.rb
sentry-ruby-0.1.2 lib/sentry/interfaces/stacktrace.rb
sentry-ruby-0.1.1 lib/sentry/interfaces/stacktrace.rb