Module: NcsNavigator::Warehouse::StringifyTrace Private

Included in:
TransformLoad, Transformers::EnumTransformer, Transformers::SqlTransformer
Defined in:
lib/ncs_navigator/warehouse/stringify_trace.rb

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Class Method Summary collapse

Class Method Details

.stringify_trace(backtrace) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Utility to generate a nicely formatted string from a ruby exception trace.

Parameters:

  • backtrace (Array<String>)

Returns:

  • String



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/ncs_navigator/warehouse/stringify_trace.rb', line 13

def stringify_trace(backtrace)
  # an array of arrays containing [filename, line, msg]
  trace_lines = backtrace.collect { |l| l.scan(/^(.*?)\:(\d*)\:?(.*)$/).first || ['', '', l] }

  lengths = trace_lines.inject([0, 0, 0]) { |lens, components|
    0.upto(2) { |i| lens[i] = [lens[i], components[i].length].max }
    lens
  }

  formats = ["%#{lengths[0]}s", "%#{lengths[1]}s", "%s"]
  trace_lines.collect { |components|
    formats.zip(components).collect { |format, component|
      (format % component)
    }.select { |s| s =~ /\S/ }.join(':')
  }.join("\n")
end