pretty_debug 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/pretty_debug.rb +39 -16
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3372f676070f6a1209686705bac0b4ae7a107781
|
4
|
+
data.tar.gz: 3d9249542e962fb8272bc97f77025b05a5f35360
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 20f1867e724f838a20b0b52951cb79260617742129bb1e94742f9e0a4d7c698749ac8a678a7cd7d329400bf5a62bb0082cde83ef7ad8b6905d32136449e0f40a
|
7
|
+
data.tar.gz: 124d332e151d164cb3f5188758084d74993f0c8d2c0ac40d3e86b1b5bb933dcfd47928f86676d83b6dae544bb344f8ae7c8cdcb6a5a70388b0227ca5092724a0
|
data/lib/pretty_debug.rb
CHANGED
@@ -2,13 +2,41 @@
|
|
2
2
|
require "string"
|
3
3
|
require "utility"
|
4
4
|
|
5
|
+
class Exception
|
6
|
+
attr_accessor :backtrace_locations
|
7
|
+
def complement_backtrace_locations
|
8
|
+
@backtrace_locations ||=
|
9
|
+
backtrace.map{|l| Thread::Backtrace::PseudoLocation.new(l)}
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class Thread::Backtrace::PseudoLocation
|
14
|
+
Pattern = /\A(?'f'.+?):(?'li'\d+)(?::in `(?'lb'.*)'|(?'lb'.*))?\z/m
|
15
|
+
attr_accessor :to_s, :absolute_path, :lineno, :label, :path, :base_label
|
16
|
+
def initialize to_s
|
17
|
+
@to_s = to_s
|
18
|
+
@absolute_path, @lineno, @label =
|
19
|
+
@to_s.match(Pattern).chain{|m| [m[:f], m[:li].to_i, m[:lb]]}
|
20
|
+
@path = File.basename(@absolute_path)
|
21
|
+
@base_label = @label.gsub(/\Ablock in /, "")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
5
25
|
module Kernel
|
26
|
+
alias old_raise :raise
|
27
|
+
def raise *args
|
28
|
+
old_raise *args
|
29
|
+
rescue => e
|
30
|
+
e.backrace_locations = caller_locations
|
31
|
+
old_raise(e)
|
32
|
+
end
|
6
33
|
at_exit do
|
7
34
|
case $!
|
8
35
|
when nil, SystemExit, Interrupt
|
9
36
|
else
|
10
|
-
puts
|
11
|
-
|
37
|
+
puts \
|
38
|
+
PrettyDebug.message($!),
|
39
|
+
PrettyDebug.backtrace_locations($!).align.map{|row| row.join(":")}
|
12
40
|
end
|
13
41
|
$stderr.reopen(IO::NULL)
|
14
42
|
$stdout.reopen(IO::NULL)
|
@@ -16,27 +44,22 @@ module Kernel
|
|
16
44
|
end
|
17
45
|
|
18
46
|
class PrettyDebug
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
47
|
+
def self.message e
|
48
|
+
e.complement_backtrace_locations
|
49
|
+
e.message.dup.tap{|s| s[0] = s[0].upcase}.sub(/(?<=[^.])\z/, ".")
|
50
|
+
end
|
51
|
+
def self.backtrace_locations e
|
52
|
+
e.complement_backtrace_locations
|
53
|
+
caller_locations(e.backtrace_locations)
|
26
54
|
end
|
27
|
-
def self.
|
28
|
-
|
29
|
-
return [] if stack.to_a.empty?
|
30
|
-
caller_file_i = $LOADED_FEATURES.index(caller_location(0).path).to_i
|
31
|
-
stack
|
55
|
+
def self.caller_locations a
|
56
|
+
a
|
32
57
|
.map{|l| [l.path.ellipsis(55), l.lineno, l.base_label]}
|
33
58
|
.transpose.tap do |_, _, m|
|
34
59
|
m.rotate!(-1)
|
35
60
|
m[0] = ""
|
36
61
|
while i = m.index{|m| m == "method_missing"}; m[i] = m[i - 1] end
|
37
62
|
end.transpose
|
38
|
-
# .reject{|f, _, _| $LOADED_FEATURES.include?(f)}
|
39
|
-
# .reject{|f, _, _| $LOADED_FEATURES.index(f).to_i > caller_file_i}
|
40
63
|
end
|
41
64
|
end
|
42
65
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pretty_debug
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sawa
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-08-
|
11
|
+
date: 2013-08-14 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: ''
|
14
14
|
email: []
|