Sha256: 7e3712b2e4002c607dcf78fa0013896b03cb8395b2fa23f36974a25198a1bf68

Contents?: true

Size: 957 Bytes

Versions: 1

Compression:

Stored size: 957 Bytes

Contents

# frozen_string_literal: true

module ElasticAPM
  class Stacktrace
    # @api private
    class Frame
      include NaivelyHashable

      attr_accessor(
        :abs_path,
        :filename,
        :function,
        :vars,
        :pre_context,
        :context_line,
        :post_context,
        :in_app,
        :lineno,
        :module,
        :colno
      )

      # rubocop:disable Metrics/AbcSize
      def build_context(context_line_count)
        return unless abs_path

        file_lines = [nil] + read_lines(abs_path)

        self.context_line = file_lines[lineno]
        self.pre_context =
          file_lines[(lineno - context_line_count - 1)...lineno]
        self.post_context =
          file_lines[(lineno + 1)..(lineno + context_line_count)]
      end
      # rubocop:enable Metrics/AbcSize

      private

      def read_lines(path)
        File.readlines(path)
      rescue Errno::ENOENT
        []
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
elastic-apm-0.2.0 lib/elastic_apm/stacktrace/frame.rb