Sha256: 24f65fd0ca0f6732f551a9233190b3ff45b1b0d4a070e29c6f013d4bf8cc9b7b

Contents?: true

Size: 1.09 KB

Versions: 4

Compression:

Stored size: 1.09 KB

Contents

module SolidErrors
  class Backtrace
    # Holder for an Array of Backtrace::Line instances.
    attr_reader :lines, :application_lines

    def self.parse(ruby_backtrace, opts = {})
      ruby_lines = ruby_backtrace.to_a

      lines = ruby_lines.collect do |unparsed_line|
        BacktraceLine.parse(unparsed_line.to_s, opts)
      end.compact

      new(lines)
    end

    def initialize(lines)
      self.lines = lines
      self.application_lines = lines.select(&:application?)
    end

    # Convert Backtrace to array.
    #
    # Returns array containing backtrace lines.
    def to_ary
      lines.take(1000).map { |l| {number: l.filtered_number, file: l.filtered_file, method: l.filtered_method, source: l.source} }
    end
    alias_method :to_a, :to_ary

    # JSON support.
    #
    # Returns JSON representation of backtrace.
    def as_json(options = {})
      to_ary
    end

    def to_s
      lines.map(&:to_s).join("\n")
    end

    def inspect
      "<Backtrace: " + lines.collect { |line| line.inspect }.join(", ") + ">"
    end

    private

    attr_writer :lines, :application_lines
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
solid_errors-0.3.3 app/models/solid_errors/backtrace.rb
solid_errors-0.3.2 app/models/solid_errors/backtrace.rb
solid_errors-0.3.1 app/models/solid_errors/backtrace.rb
solid_errors-0.3.0 app/models/solid_errors/backtrace.rb