Class: PrettyDebug

Inherits:
Object show all
Defined in:
lib/pretty_debug.rb

Constant Summary collapse

Stackline =
/\A(?'f'.+?):(?'l'\d+)(?::in `(?'m'.*)'|(?'m'.*))?\z/m
NoncallLine =
/\Ablock(?: \(\d+ levels\))? in |\A\</

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#backtraceObject

Returns the value of attribute backtrace.



55
56
57
# File 'lib/pretty_debug.rb', line 55

def backtrace
  @backtrace
end

#messageObject

Returns the value of attribute message.



55
56
57
# File 'lib/pretty_debug.rb', line 55

def message
  @message
end

Class Method Details

.clean(stack) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/pretty_debug.rb', line 66

def self.clean stack
  raise "Cannot parse. No backtrace given" unless stack
  return [] if stack.empty?
  caller_file_i = $LOADED_FEATURES.index(caller.first.match(Stackline)[:f]).to_i
  stack
  .map{|l| m = l.match(Stackline); [m[:f].ellipsis(55), m[:l].to_i, m[:m]]}
  .transpose.tap do |_, _, m|
    m.rotate!(-1)
    m[0] = ""
    while i = m.index{|m| m == "method_missing"}; m[i] = m[i - 1] end
  end.transpose
  .reject{|_, _, m| m =~ NoncallLine}
#   .reject{|f, _, _| $LOADED_FEATURES.include?(f)}
#   .reject{|f, _, _| $LOADED_FEATURES.index(f).to_i > caller_file_i}
end

.messageObject



65
# File 'lib/pretty_debug.rb', line 65

def self.message; $!.message.dup.tap{|s| s[0] = s[0].upcase}.sub(/(?<=[^.])\z/, ".") end

.new_internalObject



56
57
58
59
60
61
62
# File 'lib/pretty_debug.rb', line 56

def self.new_internal
  new.tap do |error|
    called_location = clean(caller)[2]
    error.backtrace = clean($@).take_while{|a| a != called_location}
    error.message = $!.message
  end
end