Class: PrettyTrace::StructuredBacktrace

Inherits:
Object
  • Object
show all
Defined in:
lib/pretty_trace/structured_backtrace.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(backtrace, options = {}) ⇒ StructuredBacktrace

Returns a new instance of StructuredBacktrace.



5
6
7
8
# File 'lib/pretty_trace/structured_backtrace.rb', line 5

def initialize(backtrace, options = {})
  @options = options
  @backtrace = backtrace
end

Instance Attribute Details

#backtraceObject (readonly)

Returns the value of attribute backtrace.



3
4
5
# File 'lib/pretty_trace/structured_backtrace.rb', line 3

def backtrace
  @backtrace
end

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'lib/pretty_trace/structured_backtrace.rb', line 3

def options
  @options
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/pretty_trace/structured_backtrace.rb', line 29

def empty?
  formatted_backtrace.empty?
end

#formatted_backtraceObject



21
22
23
# File 'lib/pretty_trace/structured_backtrace.rb', line 21

def formatted_backtrace
  structure.map(&:formatted_line)
end

#structureObject



10
11
12
13
14
15
16
17
18
19
# File 'lib/pretty_trace/structured_backtrace.rb', line 10

def structure
  result = backtrace_list.map { |line| BacktraceItem.new line }
  result = if should_trim? result
    result.group_by(&:path).flat_map { |_, items| [items.first, items.last].uniq }
  else
    result
  end

  should_reverse? ? result.reverse : result
end

#to_sObject



25
26
27
# File 'lib/pretty_trace/structured_backtrace.rb', line 25

def to_s
  formatted_backtrace.join "\n"
end