pretty_debug 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pretty_debug.rb +19 -9
- 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: e2fe360709694df770ac9816f66844019aac01f0
|
4
|
+
data.tar.gz: db2adaf54e01f67d0eb2857d448e50b172c5dd76
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a797553c4bf4461cb48fe93b7df4f30a5294269523ceff8a51c8dc698a0564afb014d6ae2fd9fc4fdb11ddef7e092a0dfa777982dde59a0f2833c28025bfac3b
|
7
|
+
data.tar.gz: 5a2d10201561d368334e74e614ce0235c1fde0e8da626aeed8bb1b47934684052987588a90802d56beeb735dd9abd2c3a8e004ed83d83cb727683d5d66d9786d
|
data/lib/pretty_debug.rb
CHANGED
@@ -5,14 +5,10 @@ require "ruby-prof"
|
|
5
5
|
module Kernel
|
6
6
|
at_exit do
|
7
7
|
case $!
|
8
|
-
when SystemStackError
|
9
|
-
puts PrettyDebug.mesage
|
10
|
-
##TODO Parse the backtrace and attempt to extract a call cycle.
|
11
|
-
# PrettyDebug.clean($@)
|
12
8
|
when nil, SystemExit, Interrupt
|
13
9
|
else
|
14
10
|
puts PrettyDebug.message
|
15
|
-
puts PrettyDebug.clean($@).align(":")
|
11
|
+
puts PrettyDebug.clean($@).align(":")
|
16
12
|
end
|
17
13
|
$stderr.reopen(IO::NULL)
|
18
14
|
$stdout.reopen(IO::NULL)
|
@@ -26,6 +22,10 @@ class Object
|
|
26
22
|
def case? *kases; kases.any?{|kase| kase === self} end
|
27
23
|
end
|
28
24
|
|
25
|
+
class Module
|
26
|
+
def basename; to_s.split("::").last end
|
27
|
+
end
|
28
|
+
|
29
29
|
class Array
|
30
30
|
def compatible? other
|
31
31
|
other.case?(Array) and
|
@@ -39,6 +39,16 @@ class Hash
|
|
39
39
|
other.size == size and
|
40
40
|
other.keys.all?{|k| key?(k)}
|
41
41
|
end
|
42
|
+
def ltsv *args
|
43
|
+
if args.empty? then
|
44
|
+
map{|k, v| "#{k}:#{v.to_s.tr("\t", " ")}"} else
|
45
|
+
args.map{|k| "#{k}:#{self[k].to_s.tr("\t", " ")}"}
|
46
|
+
end.join("\t")
|
47
|
+
end
|
48
|
+
end
|
49
|
+
class String
|
50
|
+
def terminal_escape; "\"#{self}\"" end
|
51
|
+
def parse_ltsv; Hash[chomp.split("\t").map{|f| f.split(":", 2)}] end
|
42
52
|
end
|
43
53
|
|
44
54
|
class PrettyDebug
|
@@ -79,7 +89,7 @@ class Object
|
|
79
89
|
tap{|x| puts "[Debug] #{caller[2][/.*?:\d+/]}:".color(:yellow); pr ? pr.call(x) : p(x)}
|
80
90
|
end
|
81
91
|
def forwardtrace sym
|
82
|
-
tap{puts "#{inspect}##{sym} defined at:", method(sym).source_location.join(":")
|
92
|
+
tap{puts "#{inspect}##{sym} defined at:", method(sym).source_location.join(":")}
|
83
93
|
end
|
84
94
|
def follow m; tap{puts "Next step: #{method(m).source_location
|
85
95
|
.chain{|a| a ? a.join(":") : "Unknown #{self}.#{m}"}
|
@@ -140,7 +150,7 @@ end
|
|
140
150
|
class Hash
|
141
151
|
KeyLengthMax = 30
|
142
152
|
def inspect
|
143
|
-
keys = self.keys.map
|
153
|
+
keys = self.keys.map(&:inspect)
|
144
154
|
# When `self == empty?`, `...max` becomes `nil`. `to_i` turns it to `0`.
|
145
155
|
w = keys.map(&:length).max.to_i.at_most(KeyLengthMax)
|
146
156
|
[keys, values].parallel{|k, v| "#{k.ljust(w)} => #{v.inspect}"}
|
@@ -164,11 +174,11 @@ module Test
|
|
164
174
|
puts "#{title}. Succeeded (#{"%.2e" % t.till_now} secs)".color(:green)
|
165
175
|
else
|
166
176
|
puts "#{title}. Failed".color(:red),
|
167
|
-
*(testee_refer.map{|o| o.inspect.
|
177
|
+
*(testee_refer.map{|o| o.inspect.color(:red)} unless testee_refer.empty?)
|
168
178
|
end
|
169
179
|
rescue Exception
|
170
180
|
puts "#{title} ... Test Error".color(:red),
|
171
|
-
[$!.message, *PrettyDebug.clean($@).align(":")].map{|l| l.
|
181
|
+
[$!.message, *PrettyDebug.clean($@).align(":")].map{|l| l.color(:red)}
|
172
182
|
end
|
173
183
|
end
|
174
184
|
|