Class: Myco::Backtrace

Inherits:
Rubinius::Backtrace show all
Defined in:
lib/myco/backtrace.rb

Instance Method Summary collapse

Methods inherited from Rubinius::Backtrace

backtrace

Constructor Details

#initializeBacktrace

Returns a new instance of Backtrace.



10
11
12
13
14
# File 'lib/myco/backtrace.rb', line 10

def initialize(*)
  super
  @gem_color = "\033[0;36m"
  @gem_paths = [Rubinius::GEMS_PATH, Rubinius::RUNTIME_PATH]
end

Instance Method Details

#show(sep = "\n", show_color = true) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/myco/backtrace.rb', line 16

def show(sep="\n", show_color=true)
  show_color &&= @colorize
  clear = show_color ? "\033[0m" : ""
  bold  = show_color ? "\033[1m" : ""
  sbullet = "{"
  ebullet = "}"
  
  @locations.map do |loc|
    file = (loc.position(Dir.getwd) || "").sub /(\:\d+)$/, ' \1'
    color = show_color ? color_from_loc(file, false) : ""
    color = @gem_color if try_gem_path file
    file_width = file.length + 1 + sbullet.length
    
    place = loc.instance_variable_get(:@method_module).to_s + '#'
    place += loc.method.name.to_s
    place_width = place.length + 1 + ebullet.length
    
    padding = @width - file_width - place_width
    padding += @width until padding >= 0
    
    file_line  = bold + color + sbullet + ' ' + clear + color + file
    place_line = color + bold + place + ' ' + ebullet + clear
    
    output = file_line + ' '*padding + place_line
    output = nil if file == "(myco_internal) :1"
    output
  end.compact.reverse.join sep
end

#try_gem_path(file) ⇒ Object

If file is in one of the GEM_PATHs, mutate the string and return true



46
47
48
49
50
51
52
53
54
55
# File 'lib/myco/backtrace.rb', line 46

def try_gem_path file
  @gem_paths.each do |gem_path|
    if file.start_with? gem_path and not gem_path.empty?
      file.sub! File.join(gem_path, 'gems'), ''
      file.sub! %r{/[^/]*/}, ''
      return true
    end
  end
  return false
end