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



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

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

.strip_cwd_backtrace(backtrace) ⇒ Object



40
41
42
# File 'lib/rib/core/strip_backtrace.rb', line 40

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

.strip_home_backtrace(backtrace) ⇒ Object



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

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

.strip_lib_backtrace(backtrace) ⇒ Object



44
45
46
47
# File 'lib/rib/core/strip_backtrace.rb', line 44

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

Instance Method Details

#format_error(err) ⇒ Object

strip backtrace until rib



11
12
13
14
15
16
17
18
19
20
# File 'lib/rib/core/strip_backtrace.rb', line 11

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

#get_error(err, backtrace = err.backtrace) ⇒ Object

————— Plugin API —————



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

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