Method: RMTools.format_trace

Defined in:
lib/rmtools/dev/trace_format.rb

.format_trace(a) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/rmtools/dev/trace_format.rb', line 30

def format_trace(a)
  return [] if a.empty?
  
  bt, steps, i = [], [], 0
  m = a[0].parse:caller
  # seems like that bug is fixed for now
  #m.line -= 1 if m and m.file =~ /\.haml$/
  
  while i < a.size
    m2 = a[i+1] && a[i+1].parse(:caller)
    #m2.line -= 1 if m2 and m2.file =~ /\.haml$/
    if m and m.path !~ IgnoreFiles
      step = a[i]
      if step["\n"] # already formatted
        bt << step
      else
        if m.block_level # > 1.9
          step = step.sub(/block (\(\d+ levels\) )?in/, '{'+m.block_level+'}')
        end
        if m and m.func and m2 and [m.path, m.line] == [m2.path, m2.line]
          steps << " -> `#{'{'+m.block_level+'} ' if m.block_level}#{m.func}'"
        elsif m and m.line != 0 and line = RMTools.highlighted_line(m.path, m.line)
          bt << "#{step}#{steps.join}\n#{line}"
          steps = []
        else
          bt << step
        end
      end
    end
    i += 1
    m = m2
  end
  bt
end