Module: Rib::StripBacktrace

Extended by:
Plugin
Defined in:
lib/rib/core/strip_backtrace.rb

Instance Attribute Summary

Attributes included from Plugin

#disabled

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Plugin

disable, disabled?, enable, enabled?, extended

Class Method Details

.strip_backtrace(backtrace) ⇒ Object



24
25
26
# File 'lib/rib/core/strip_backtrace.rb', line 24

def strip_backtrace backtrace
  strip_home_backtrace(strip_cwd_backtrace(strip_lib_backtrace(backtrace)))
end

.strip_cwd_backtrace(backtrace) ⇒ Object



32
33
34
# File 'lib/rib/core/strip_backtrace.rb', line 32

def strip_cwd_backtrace backtrace
  backtrace.map{ |path| path.sub(Dir.pwd, '.') }
end

.strip_home_backtrace(backtrace) ⇒ Object



28
29
30
# File 'lib/rib/core/strip_backtrace.rb', line 28

def strip_home_backtrace backtrace
  backtrace.map{ |path| path.sub(ENV['HOME'], '~') }
end

.strip_lib_backtrace(backtrace) ⇒ Object



36
37
38
39
# File 'lib/rib/core/strip_backtrace.rb', line 36

def strip_lib_backtrace backtrace
  backtrace[
    0..backtrace.rindex{ |l| l =~ /\(#{name}\):\d+:in `.+?'/ } || -1]
end

Instance Method Details

#format_error(err) ⇒ Object

————— Rib API —————



10
11
12
13
14
# File 'lib/rib/core/strip_backtrace.rb', line 10

def format_error err
  return super if StripBacktrace.disabled?
  message, backtrace = get_error(err)
  "#{message}\n  #{backtrace.join("\n  ")}"
end

#get_error(err) ⇒ Object



16
17
18
19
# File 'lib/rib/core/strip_backtrace.rb', line 16

def get_error err
  return super if StripBacktrace.disabled?
  ["#{err.class}: #{err.message}", strip_backtrace(err.backtrace)]
end