pretty_debug 0.7.0 → 0.7.1
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 +63 -78
- 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: 9bcc106c04435a098dfb7f2750a1108c2bcd8880
|
4
|
+
data.tar.gz: ea4f672bf299a4a2fbd5ae90d24d172bb6ff9717
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6cf7a2711b1c9028882d73588ec313e5400a29d1fe4b73332c5b5969d663a60e80e65a483bbe6f0900859e770977dc32c1ffa0a2586559383c747d98aaabdda6
|
7
|
+
data.tar.gz: 5b45b1c5eafadc04021b56f9178d4d556963fd1af5d24951b3dca813fa644bdf834d077c2f84a798b95c31e9d7156e30b9308662a334c89bebcf46a1782774c4
|
data/lib/pretty_debug.rb
CHANGED
@@ -9,12 +9,6 @@ require "compact_time"
|
|
9
9
|
class File
|
10
10
|
def self.relativize f; f.sub(%r{\A/}, "".freeze) end
|
11
11
|
def self.expand_path_relative f; expand_path(f, caller_location.dirname) end
|
12
|
-
def self.add f, s
|
13
|
-
open(f, "a+".freeze) do |io|
|
14
|
-
io.readlines.last.tap{|l| io.puts if l && l.end_with?($/).!}
|
15
|
-
io.write(s)
|
16
|
-
end
|
17
|
-
end
|
18
12
|
end
|
19
13
|
|
20
14
|
class Dir
|
@@ -23,45 +17,23 @@ end
|
|
23
17
|
|
24
18
|
module Kernel
|
25
19
|
def caller_location i = 1; caller_locations(i + 1, 1).first end
|
26
|
-
def load_relative f, *rest;
|
27
|
-
load(File.expand_path(f, caller_location.dirname), *rest)
|
28
|
-
end
|
20
|
+
def load_relative f, *rest; load(File.expand_path(f, caller_location.dirname), *rest) end
|
29
21
|
end
|
30
22
|
|
31
23
|
#############################################
|
32
|
-
#
|
24
|
+
# Debug
|
33
25
|
#############################################
|
34
26
|
|
35
|
-
class
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
def ellipsis n
|
42
|
-
if length <= n then self
|
43
|
-
elsif n.odd? then "#{slice(0..n/2-3)}...#{slice(-n/2+2..-1)}"
|
44
|
-
else "#{slice(0..n/2-3)}...#{slice(-n/2+1..-1)}"
|
27
|
+
class Object
|
28
|
+
def intercept &pr
|
29
|
+
l = caller_location
|
30
|
+
tap do |x| puts \
|
31
|
+
"[Debug] #{"#{l.path}:#{l.lineno}"}".color(:yellow),
|
32
|
+
(pr ? pr.call(x) : x).inspect.verbatim.unchomp
|
45
33
|
end
|
46
34
|
end
|
47
|
-
def write_to f; write_to!(f) rescue nil end
|
48
|
-
def write_to! f; File.write(f, self) end
|
49
|
-
def binary_write_to f; binary_write_to!(f) rescue nil end
|
50
|
-
def binary_write_to! f; File.write(f, self, "wb".freeze) end
|
51
|
-
def add_to f; add_to!(f) rescue nil end
|
52
|
-
def add_to! f; File.add(f, self) end
|
53
|
-
# Raises an error if either save, read, or round-trip-matching fails.
|
54
|
-
def safely_write_to dest, tmp = "#{Dir.tmpdir}/safe-save"
|
55
|
-
write_to!(tmp)
|
56
|
-
raise "Round trip `save-read` failed on `#{dest}`." unless File.read(tmp) == self
|
57
|
-
File.rename(tmp, dest)
|
58
|
-
end
|
59
35
|
end
|
60
36
|
|
61
|
-
#############################################
|
62
|
-
#
|
63
|
-
#############################################
|
64
|
-
|
65
37
|
module Kernel
|
66
38
|
def class_check v, klass, &pr
|
67
39
|
unless v.kind_of?(klass)
|
@@ -124,11 +96,6 @@ module Kernel
|
|
124
96
|
end
|
125
97
|
end
|
126
98
|
|
127
|
-
class PrettyArray < Array
|
128
|
-
def to_puts; align.map(&PrettyDebug.instance_variable_get(:@format)) end
|
129
|
-
def inspect; to_puts.join($/) end
|
130
|
-
end
|
131
|
-
|
132
99
|
class PrettyDebug
|
133
100
|
def self.reject &pr
|
134
101
|
reject = @reject
|
@@ -144,7 +111,7 @@ class PrettyDebug
|
|
144
111
|
m =~ /\A<.*>\z/ # Such as `<top (required)>`, `<module:Foo>`.
|
145
112
|
}
|
146
113
|
@select = ->f, m{true}
|
147
|
-
format{|row| "
|
114
|
+
format{|row| "#{row.join(" | ".freeze)} ".bg(:black).color(:yellow)}
|
148
115
|
def self.message e
|
149
116
|
e.complement_backtrace_locations
|
150
117
|
e.message.dup.tap{|s| s[0] = s[0].upcase unless s.empty?}.sub(/(?<=[^.])\z/, ".".freeze)
|
@@ -194,17 +161,24 @@ class PrettyDebug
|
|
194
161
|
end
|
195
162
|
end
|
196
163
|
|
164
|
+
#############################################
|
165
|
+
# Inspection
|
166
|
+
#############################################
|
167
|
+
|
168
|
+
class PrettyArray < Array
|
169
|
+
def to_puts; align.map(&PrettyDebug.instance_variable_get(:@format)) end
|
170
|
+
def inspect; to_puts.join($/) end
|
171
|
+
end
|
172
|
+
|
197
173
|
class Proc
|
198
174
|
def inspect; f, l = source_location; "Proc@#{f}:#{l}"
|
199
175
|
rescue; "Proc@source_unknown".freeze
|
200
176
|
end
|
201
177
|
end
|
178
|
+
|
202
179
|
class Method; def inspect; "#{receiver}.#{name}" end end
|
203
|
-
class UnboundMethod; def inspect; "#{owner}##{name}" end end
|
204
180
|
|
205
|
-
|
206
|
-
# Terminal
|
207
|
-
#############################################
|
181
|
+
class UnboundMethod; def inspect; "#{owner}##{name}" end end
|
208
182
|
|
209
183
|
class Array
|
210
184
|
SingleLength = 50
|
@@ -213,28 +187,6 @@ class Array
|
|
213
187
|
length < 2 || s.map(&:length).inject(:+) < SingleLength ?
|
214
188
|
"[#{s.join(", ".freeze)}]" : "[#$/#{s.join(",#$/".freeze).indent}#$/]"
|
215
189
|
end
|
216
|
-
def align ellipsis_limit = nil
|
217
|
-
transpose.map do |col|
|
218
|
-
just = case col.first; when Numeric then :rjust; else :ljust end
|
219
|
-
width = col.map{|cell| cell.to_s.length}.max
|
220
|
-
max = ellipsis_limit || width
|
221
|
-
col.map{|cell| cell.to_s.ellipsis(max).__send__(just, width > max ? max : width)}
|
222
|
-
end.transpose
|
223
|
-
end
|
224
|
-
def common_prefix
|
225
|
-
each{|e| class_check(e, String){"All elements must be a String".freeze}}
|
226
|
-
first, *others = self
|
227
|
-
i = 0
|
228
|
-
loop{break unless first[i] and others.all?{|s| first[i] == s[i]}; i += 1}
|
229
|
-
first[0, i]
|
230
|
-
end
|
231
|
-
def common_affix
|
232
|
-
each{|e| class_check(e, String){"All elements must be a String".freeze}}
|
233
|
-
first, *others = self
|
234
|
-
i = - 1
|
235
|
-
loop{break unless first[i] and others.all?{|s| first[i] == s[i]}; i -= 1}
|
236
|
-
first[i + 1, -(i + 1)]
|
237
|
-
end
|
238
190
|
end
|
239
191
|
|
240
192
|
class Hash
|
@@ -251,16 +203,6 @@ class Hash
|
|
251
203
|
end
|
252
204
|
end
|
253
205
|
|
254
|
-
class Object
|
255
|
-
def intercept &pr
|
256
|
-
l = caller_location
|
257
|
-
tap do |x| puts \
|
258
|
-
"[Debug] #{"#{l.path}:#{l.lineno}"}".color(:yellow),
|
259
|
-
(pr ? pr.call(x) : x).inspect.verbatim.unchomp
|
260
|
-
end
|
261
|
-
end
|
262
|
-
end
|
263
|
-
|
264
206
|
#############################################
|
265
207
|
# Terminal
|
266
208
|
#############################################
|
@@ -284,3 +226,46 @@ class String
|
|
284
226
|
private
|
285
227
|
def vt100 s = "".freeze; "\e[#{s}m" end
|
286
228
|
end
|
229
|
+
|
230
|
+
#############################################
|
231
|
+
# String Formatting
|
232
|
+
#############################################
|
233
|
+
|
234
|
+
class Array
|
235
|
+
def align ellipsis_limit = nil
|
236
|
+
transpose.map do |col|
|
237
|
+
just = case col.first; when Numeric then :rjust; else :ljust end
|
238
|
+
width = col.map{|cell| cell.to_s.length}.max
|
239
|
+
max = ellipsis_limit || width
|
240
|
+
col.map{|cell| cell.to_s.ellipsis(max).__send__(just, width > max ? max : width)}
|
241
|
+
end.transpose
|
242
|
+
end
|
243
|
+
def common_prefix
|
244
|
+
each{|e| class_check(e, String){"All elements must be a String".freeze}}
|
245
|
+
first, *others = self
|
246
|
+
i = 0
|
247
|
+
loop{break unless first[i] and others.all?{|s| first[i] == s[i]}; i += 1}
|
248
|
+
first[0, i]
|
249
|
+
end
|
250
|
+
def common_affix
|
251
|
+
each{|e| class_check(e, String){"All elements must be a String".freeze}}
|
252
|
+
first, *others = self
|
253
|
+
i = - 1
|
254
|
+
loop{break unless first[i] and others.all?{|s| first[i] == s[i]}; i -= 1}
|
255
|
+
first[i + 1, -(i + 1)]
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
class String
|
260
|
+
@@indent = " "
|
261
|
+
def indent n = 1; gsub(/^/, @@indent * n) end
|
262
|
+
def unindent; gsub(/^#{match(/^\s+/)}/, "".freeze).chomp end
|
263
|
+
def unchomp; sub(/#$/?\z/, $/) end
|
264
|
+
def unchomp!; sub!(/#$/?\z/, $/) end
|
265
|
+
def ellipsis n
|
266
|
+
if length <= n then self
|
267
|
+
elsif n.odd? then "#{slice(0..n/2-3)}...#{slice(-n/2+2..-1)}"
|
268
|
+
else "#{slice(0..n/2-3)}...#{slice(-n/2+1..-1)}"
|
269
|
+
end
|
270
|
+
end
|
271
|
+
end
|
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.7.
|
4
|
+
version: 0.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sawa
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-02-
|
11
|
+
date: 2014-02-26 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: ''
|
14
14
|
email: []
|