pretty_backtrace 0.0.1 → 0.0.2
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/README.md +36 -6
- data/lib/pretty_backtrace.rb +16 -5
- data/lib/pretty_backtrace/version.rb +1 -1
- data/test.rb +3 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3971218f377ecdef54fa8b356ccc3c02ac4335cb
|
4
|
+
data.tar.gz: 04f0c5fa5a805cbbb23292f6068af5a3ca6a4b28
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 66899e9934ad1a5e2cd125483146a6e33b7702e632f4aa7aeeb34e25ec91b16081f1bb9bfe68e738ca710e022f782ced1de6100deb89b0053c5930ce3f8b1148
|
7
|
+
data.tar.gz: 315156aab1dc90a8c2438550c058df9b990c5bb79b6f60e556d393470651076ac35c0be4e53f800ba41a0f9b6f93e25b980385a38d8dec744c51d321295d10ac
|
data/README.md
CHANGED
@@ -27,7 +27,7 @@ require 'pretty_backtrace'
|
|
27
27
|
PrettyBacktrace.enable
|
28
28
|
|
29
29
|
def recursive n
|
30
|
-
str = "Hi #{n}!!" * 128
|
30
|
+
str = "Hi #{n}!! " * 128
|
31
31
|
if n > 0
|
32
32
|
recursive n - 1
|
33
33
|
else
|
@@ -41,17 +41,47 @@ recursive 3
|
|
41
41
|
and you can see prettier backtrace (you can see local variable names and values).
|
42
42
|
|
43
43
|
```
|
44
|
-
test.rb:10:in `recursive' (n = 0, str = "Hi 0!!Hi 0!!Hi 0
|
45
|
-
from test.rb:
|
46
|
-
from test.rb:
|
47
|
-
from test.rb:
|
48
|
-
from test.rb:
|
44
|
+
test.rb:10:in `recursive' (n = 0, str = "Hi 0!! Hi 0!! Hi 0...): bottom of recursive (RuntimeError)
|
45
|
+
from test.rb:9:in `recursive' (n = 1, str = "Hi 1!! Hi 1!! Hi 1...)
|
46
|
+
from test.rb:9:in `recursive' (n = 2, str = "Hi 2!! Hi 2!! Hi 2...)
|
47
|
+
from test.rb:9:in `recursive' (n = 3, str = "Hi 3!! Hi 3!! Hi 3...)
|
48
|
+
from test.rb:15:in `<main>'
|
49
49
|
```
|
50
50
|
|
51
51
|
You only need to require "pretty_backtrace/enable" to eliminate "PrettyBacktrace.enable call".
|
52
52
|
|
53
53
|
PrettyBacktrace::CONFIG can change behaviour. See source code files for details.
|
54
54
|
|
55
|
+
### Multi-line mode
|
56
|
+
|
57
|
+
You can use multi-line mode with the following configuration.
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
PrettyBacktrace::CONFIG[:multi_line] = true
|
61
|
+
```
|
62
|
+
|
63
|
+
Multi-line mode enable to show all variables (and pointing values) in each lines like that:
|
64
|
+
|
65
|
+
```
|
66
|
+
test.rb:11:in `recursive'
|
67
|
+
n = 0
|
68
|
+
str = "Hi 0!! Hi 0!! Hi 0!! Hi 0!! Hi 0!! Hi 0!! Hi 0!! Hi 0...
|
69
|
+
: bottom of recursive (RuntimeError)
|
70
|
+
from test.rb:9:in `recursive'
|
71
|
+
n = 1
|
72
|
+
str = "Hi 1!! Hi 1!! Hi 1!! Hi 1!! Hi 1!! Hi 1!! Hi 1!! Hi 1...
|
73
|
+
|
74
|
+
from test.rb:9:in `recursive'
|
75
|
+
n = 2
|
76
|
+
str = "Hi 2!! Hi 2!! Hi 2!! Hi 2!! Hi 2!! Hi 2!! Hi 2!! Hi 2...
|
77
|
+
|
78
|
+
from test.rb:9:in `recursive'
|
79
|
+
n = 3
|
80
|
+
str = "Hi 3!! Hi 3!! Hi 3!! Hi 3!! Hi 3!! Hi 3!! Hi 3!! Hi 3...
|
81
|
+
|
82
|
+
from test.rb:15:in `<main>'
|
83
|
+
```
|
84
|
+
|
55
85
|
## Contributing
|
56
86
|
|
57
87
|
There are no spec tests. I love to get your contributions!
|
data/lib/pretty_backtrace.rb
CHANGED
@@ -5,6 +5,9 @@ module PrettyBacktrace
|
|
5
5
|
CONFIG = {
|
6
6
|
truncate_length: 20,
|
7
7
|
disabled_exception_classes: {},
|
8
|
+
multi_line: false,
|
9
|
+
multi_line_truncate_length: 60,
|
10
|
+
multi_line_indent: 10,
|
8
11
|
}
|
9
12
|
|
10
13
|
EXCEPTION_MODIFIER_TRACE = TracePoint.new(:raise){|tp|
|
@@ -77,11 +80,19 @@ module PrettyBacktrace
|
|
77
80
|
trace_line = backtrace_location.to_s
|
78
81
|
|
79
82
|
unless local_variables_values.empty?
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
83
|
+
if CONFIG[:multi_line]
|
84
|
+
additional = local_variables_values.map{|lv, v|
|
85
|
+
v = v[0..CONFIG[:multi_line_truncate_length]] + '...' if v.length > CONFIG[:multi_line_truncate_length]
|
86
|
+
' ' * CONFIG[:multi_line_indent] + "#{lv} = #{v.to_s}"
|
87
|
+
}.join("\n") + "\n"
|
88
|
+
trace_line = "#{trace_line}\n#{additional}"
|
89
|
+
else
|
90
|
+
additional = local_variables_values.map{|lv, v|
|
91
|
+
v = v[0..CONFIG[:truncate_length]] + '...' if v.length > CONFIG[:truncate_length]
|
92
|
+
"#{lv} = #{v.to_s}"
|
93
|
+
}.join(", ")
|
94
|
+
trace_line = "#{trace_line} (#{additional})"
|
95
|
+
end
|
85
96
|
end
|
86
97
|
|
87
98
|
trace_line
|
data/test.rb
CHANGED