debug_helper 1.0.0 → 1.5.0
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/Gemfile.lock +1 -1
- data/README.md +37 -18
- data/lib/debug_helper.rb +38 -44
- data/lib/debug_helper/version.rb +1 -1
- data/markdown/readme/classes/array/circular/show.md +1 -1
- data/markdown/readme/classes/array/circular/show.yaml +1 -1
- data/markdown/readme/classes/array/mixed/show.md +1 -1
- data/markdown/readme/classes/array/mixed/show.yaml +1 -1
- data/markdown/readme/classes/array/nested/show.md +1 -1
- data/markdown/readme/classes/array/nested/show.yaml +1 -1
- data/markdown/readme/classes/array/simple/show.md +1 -1
- data/markdown/readme/classes/array/simple/show.yaml +1 -1
- data/markdown/readme/classes/hash/circular/show.md +1 -1
- data/markdown/readme/classes/hash/circular/show.yaml +1 -1
- data/markdown/readme/classes/hash/mixed/show.md +1 -1
- data/markdown/readme/classes/hash/mixed/show.yaml +1 -1
- data/markdown/readme/classes/hash/nested/show.md +1 -1
- data/markdown/readme/classes/hash/nested/show.yaml +1 -1
- data/markdown/readme/classes/hash/simple/show.md +1 -1
- data/markdown/readme/classes/hash/simple/show.yaml +1 -1
- data/markdown/readme/classes/object/datetime/show.md +1 -1
- data/markdown/readme/classes/object/datetime/show.yaml +1 -1
- data/markdown/readme/classes/object/range/show.md +1 -1
- data/markdown/readme/classes/object/range/show.yaml +1 -1
- data/markdown/readme/classes/object/regexp/show.md +1 -1
- data/markdown/readme/classes/object/regexp/show.yaml +1 -1
- data/markdown/readme/classes/string/multiline/show.md +1 -1
- data/markdown/readme/classes/string/multiline/show.yaml +1 -1
- data/markdown/readme/classes/string/simple/show.md +1 -1
- data/markdown/readme/classes/string/simple/show.yaml +1 -1
- data/markdown/readme/classes/struct/circular/show.md +1 -1
- data/markdown/readme/classes/struct/circular/show.yaml +1 -1
- data/markdown/readme/classes/struct/mixed/show.md +1 -1
- data/markdown/readme/classes/struct/mixed/show.yaml +1 -1
- data/markdown/readme/classes/struct/nested/show.md +1 -1
- data/markdown/readme/classes/struct/nested/show.yaml +1 -1
- data/markdown/readme/classes/struct/simple/show.md +1 -1
- data/markdown/readme/classes/struct/simple/show.yaml +1 -1
- data/markdown/readme/classes/symbol/simple/show.md +1 -1
- data/markdown/readme/classes/symbol/simple/show.yaml +1 -1
- data/markdown/readme/template.md +19 -0
- 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: bcb726c44604dca3873eee267d8b1232bc55f637
|
4
|
+
data.tar.gz: 5072c0c19bdc5729bf0134a65b5f5df894a688d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e2fb59ddebe2f696de7728f28e9ec74b71f93baece609ee7d12783fd69c1ae7fad56bec37dd706d0032457b7cfe9e1bcef5022ac512e074baf8a9747c1d14806
|
7
|
+
data.tar.gz: c7241f9cfccef40479196a8c7c4def698ecef721adfd0157e086449ebada8ca60906d7e820cce4137809a35cd8c35d033974217275b3a3d157c51102e5e4ad36
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -36,6 +36,25 @@ Others are treated as:
|
|
36
36
|
|
37
37
|
- [Object](#object)
|
38
38
|
|
39
|
+
## Class Method or Module Method?
|
40
|
+
|
41
|
+
Most examples in this documentation show use of the class method:
|
42
|
+
|
43
|
+
```ruby
|
44
|
+
require 'debug_helper'
|
45
|
+
DebugHelper.show(obj, message)
|
46
|
+
```
|
47
|
+
|
48
|
+
You can also choose to use the module method, ```putd``` (Thanks, [palkan](https://www.reddit.com/user/palkan)!), which looks a lot like ```puts```.
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
require 'debug_helper'
|
52
|
+
include DebugHelper::Putd
|
53
|
+
putd obj, message
|
54
|
+
```
|
55
|
+
|
56
|
+
Just be sure to ```include DebugHelper::Putd```.
|
57
|
+
|
39
58
|
### Array
|
40
59
|
|
41
60
|
#### Simple Array
|
@@ -55,7 +74,7 @@ The output shows details of the array.
|
|
55
74
|
```show.yaml```:
|
56
75
|
```yaml
|
57
76
|
---
|
58
|
-
Array (
|
77
|
+
Array (message='My simple array' size=3):
|
59
78
|
Element 0: Fixnum 5
|
60
79
|
Element 1: Fixnum 10
|
61
80
|
Element 2: Fixnum 15
|
@@ -78,7 +97,7 @@ The output shows details of the array.
|
|
78
97
|
```show.yaml```:
|
79
98
|
```yaml
|
80
99
|
---
|
81
|
-
Array (
|
100
|
+
Array (message='My mixed array' size=3):
|
82
101
|
Element 0: Fixnum 0
|
83
102
|
Element 1:
|
84
103
|
String (size=3 encoding=UTF-8 ascii_only=true bytesize=3):
|
@@ -104,7 +123,7 @@ The output shows details of the arrays.
|
|
104
123
|
```show.yaml```:
|
105
124
|
```yaml
|
106
125
|
---
|
107
|
-
Array (
|
126
|
+
Array (message='My nested arrays' size=3):
|
108
127
|
Element 0: Fixnum 0
|
109
128
|
Element 1:
|
110
129
|
Array (size=2):
|
@@ -138,7 +157,7 @@ The circular reference is not followed.
|
|
138
157
|
```show.yaml```:
|
139
158
|
```yaml
|
140
159
|
---
|
141
|
-
Array (
|
160
|
+
Array (message='My circular arrays' size=1):
|
142
161
|
Element 0:
|
143
162
|
Array (size=1):
|
144
163
|
Element 0: Array [[[...]]]
|
@@ -162,7 +181,7 @@ The output shows details of the hash.
|
|
162
181
|
```show.yaml```:
|
163
182
|
```yaml
|
164
183
|
---
|
165
|
-
Hash (size=3
|
184
|
+
Hash (size=3 message='My simple hash'):
|
166
185
|
Pair 0:
|
167
186
|
Key:
|
168
187
|
Symbol (size=1 encoding=US-ASCII): :a
|
@@ -198,7 +217,7 @@ The output shows details of the hash.
|
|
198
217
|
```show.yaml```:
|
199
218
|
```yaml
|
200
219
|
---
|
201
|
-
Hash (size=3
|
220
|
+
Hash (size=3 message='My mixed hash'):
|
202
221
|
Pair 0:
|
203
222
|
Key:
|
204
223
|
Symbol (size=1 encoding=US-ASCII): :a
|
@@ -242,7 +261,7 @@ The output shows details of the hashes.
|
|
242
261
|
```show.yaml```:
|
243
262
|
```yaml
|
244
263
|
---
|
245
|
-
Hash (size=2
|
264
|
+
Hash (size=2 message='My nested hash'):
|
246
265
|
Pair 0:
|
247
266
|
Key:
|
248
267
|
Symbol (size=1 encoding=US-ASCII): :a
|
@@ -293,7 +312,7 @@ The circular reference is not followed.
|
|
293
312
|
```show.yaml```:
|
294
313
|
```yaml
|
295
314
|
---
|
296
|
-
Hash (size=1
|
315
|
+
Hash (size=1 message='My circular hashes'):
|
297
316
|
Pair 0:
|
298
317
|
Key:
|
299
318
|
Symbol (size=3 encoding=US-ASCII): :foo
|
@@ -324,7 +343,7 @@ The output shows details of the struct.
|
|
324
343
|
```show.yaml```:
|
325
344
|
```yaml
|
326
345
|
---
|
327
|
-
MyStruct (
|
346
|
+
MyStruct (message='My simple struct' size=3):
|
328
347
|
Member 0:
|
329
348
|
Name: :a
|
330
349
|
Value: Fixnum 0
|
@@ -354,7 +373,7 @@ The output shows details of the struct.
|
|
354
373
|
```show.yaml```:
|
355
374
|
```yaml
|
356
375
|
---
|
357
|
-
MyStruct (
|
376
|
+
MyStruct (message='My mixed struct' size=3):
|
358
377
|
Member 0:
|
359
378
|
Name: :a
|
360
379
|
Value: Fixnum 0
|
@@ -390,7 +409,7 @@ The output shows details of the structs.
|
|
390
409
|
```show.yaml```:
|
391
410
|
```yaml
|
392
411
|
---
|
393
|
-
MyStruct_0 (
|
412
|
+
MyStruct_0 (message='My nested struct' size=2):
|
394
413
|
Member 0:
|
395
414
|
Name: :a
|
396
415
|
Value:
|
@@ -436,7 +455,7 @@ The circular reference is not followed.
|
|
436
455
|
```show.yaml```:
|
437
456
|
```yaml
|
438
457
|
---
|
439
|
-
MyStruct (
|
458
|
+
MyStruct (message='My circular struct' size=3):
|
440
459
|
Member 0:
|
441
460
|
Name: :a
|
442
461
|
Value:
|
@@ -477,7 +496,7 @@ The output shows details of the string.
|
|
477
496
|
```show.yaml```:
|
478
497
|
```yaml
|
479
498
|
---
|
480
|
-
String (
|
499
|
+
String (message='My simple string' size=11 encoding=UTF-8 ascii_only=true bytesize=11):
|
481
500
|
- Lorem ipsum
|
482
501
|
```
|
483
502
|
|
@@ -501,7 +520,7 @@ The output shows details of the string.
|
|
501
520
|
```show.yaml```:
|
502
521
|
```yaml
|
503
522
|
---
|
504
|
-
String (
|
523
|
+
String (message='My multiline string' size=122 encoding=UTF-8 ascii_only=true bytesize=122):
|
505
524
|
- |
|
506
525
|
Lorem Ipsum dolor sit amet,consectetur adipisicing elit,
|
507
526
|
sed doeiusmod tempor incididunt ut laboreet dolore magna aliqua.
|
@@ -524,7 +543,7 @@ The output shows details of the symbol.
|
|
524
543
|
```show.yaml```:
|
525
544
|
```yaml
|
526
545
|
---
|
527
|
-
Symbol (
|
546
|
+
Symbol (message='My symbol' size=11 encoding=US-ASCII): :lorem_ipsum
|
528
547
|
```
|
529
548
|
### Object
|
530
549
|
|
@@ -548,7 +567,7 @@ The output shows details of the datetime.
|
|
548
567
|
|
549
568
|
```show.yaml```:
|
550
569
|
```yaml
|
551
|
-
--- DateTime (
|
570
|
+
--- DateTime (message='My datetime') 2018-07-04T14:49:11-05:00
|
552
571
|
...
|
553
572
|
```
|
554
573
|
|
@@ -568,7 +587,7 @@ The output shows details of the range.
|
|
568
587
|
|
569
588
|
```show.yaml```:
|
570
589
|
```yaml
|
571
|
-
--- Range (
|
590
|
+
--- Range (message='My range') 0..9
|
572
591
|
...
|
573
592
|
```
|
574
593
|
|
@@ -588,6 +607,6 @@ The output shows details of the regexp.
|
|
588
607
|
|
589
608
|
```show.yaml```:
|
590
609
|
```yaml
|
591
|
-
--- Regexp (
|
610
|
+
--- Regexp (message='My regexp') (?-mix:foo)
|
592
611
|
...
|
593
612
|
```
|
data/lib/debug_helper.rb
CHANGED
@@ -4,64 +4,72 @@ require 'debug_helper/version'
|
|
4
4
|
|
5
5
|
class DebugHelper
|
6
6
|
|
7
|
+
module Putd
|
8
|
+
|
9
|
+
def putd(obj, message)
|
10
|
+
DebugHelper.show(obj, message)
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
7
15
|
attr_accessor \
|
8
16
|
:obj,
|
9
|
-
:
|
17
|
+
:message,
|
10
18
|
:object_ids
|
11
19
|
|
12
|
-
def self.show(obj,
|
13
|
-
debug_helper = DebugHelper.new(obj,
|
14
|
-
x = debug_helper.send(:_show, obj,
|
20
|
+
def self.show(obj, message = obj.class)
|
21
|
+
debug_helper = DebugHelper.new(obj, message)
|
22
|
+
x = debug_helper.send(:_show, obj, message, info = {})
|
15
23
|
puts x.to_yaml
|
16
24
|
end
|
17
25
|
|
18
26
|
private
|
19
27
|
|
20
|
-
def initialize(obj,
|
28
|
+
def initialize(obj, message)
|
21
29
|
self.obj = obj
|
22
|
-
self.
|
30
|
+
self.message = message
|
23
31
|
self.object_ids = []
|
24
32
|
end
|
25
33
|
|
26
|
-
def _show(obj,
|
34
|
+
def _show(obj, message, info)
|
27
35
|
if object_ids.include?(obj.object_id)
|
28
|
-
s = show_object(obj,
|
36
|
+
s = show_object(obj, message, info)
|
29
37
|
else
|
30
38
|
object_ids.push(obj.object_id)
|
31
39
|
s = case
|
32
40
|
when obj.kind_of?(Array)
|
33
|
-
show_array(obj,
|
41
|
+
show_array(obj, message, info)
|
34
42
|
when obj.kind_of?(Hash)
|
35
|
-
show_hash(obj,
|
43
|
+
show_hash(obj, message, info)
|
36
44
|
when obj.kind_of?(String)
|
37
|
-
show_string(obj,
|
45
|
+
show_string(obj, message, info)
|
38
46
|
when obj.kind_of?(Struct)
|
39
|
-
show_struct(obj,
|
47
|
+
show_struct(obj, message, info)
|
40
48
|
when obj.kind_of?(Symbol)
|
41
|
-
show_symbol(obj,
|
49
|
+
show_symbol(obj, message, info)
|
42
50
|
# when obj.kind_of?(Range)
|
43
51
|
# when obj.kind_of?(Set)
|
44
52
|
else
|
45
|
-
show_object(obj,
|
53
|
+
show_object(obj, message, info)
|
46
54
|
end
|
47
55
|
end
|
48
56
|
object_ids.pop
|
49
57
|
s
|
50
58
|
end
|
51
59
|
|
52
|
-
def show_array(obj,
|
60
|
+
def show_array(obj, message, info)
|
53
61
|
content = {}
|
54
62
|
obj.each_with_index do |item, i|
|
55
63
|
content.store("Element #{i}", _show(item, nil, {}))
|
56
64
|
end
|
57
65
|
attrs = {
|
58
|
-
:
|
66
|
+
:message => message,
|
59
67
|
:size => obj.size,
|
60
68
|
}
|
61
69
|
_show_item(obj.class.name, content, attrs, info)
|
62
70
|
end
|
63
71
|
|
64
|
-
def show_hash(obj,
|
72
|
+
def show_hash(obj, message, info)
|
65
73
|
content = {}
|
66
74
|
obj.each_with_index do |pair, i|
|
67
75
|
key, value = *pair
|
@@ -72,19 +80,19 @@ class DebugHelper
|
|
72
80
|
:size => obj.size,
|
73
81
|
:default => obj.default,
|
74
82
|
:default_proc => obj.default_proc,
|
75
|
-
:
|
83
|
+
:message => message,
|
76
84
|
}
|
77
85
|
_show_item(obj.class.name, content, attrs, info)
|
78
86
|
end
|
79
87
|
|
80
|
-
def show_object(obj,
|
81
|
-
|
82
|
-
"#{obj.class.name}#{
|
88
|
+
def show_object(obj, message, info)
|
89
|
+
message_info = message.nil? ? '' : " (message='#{message}')"
|
90
|
+
"#{obj.class.name}#{message_info} #{obj}"
|
83
91
|
end
|
84
92
|
|
85
|
-
def show_string(obj,
|
93
|
+
def show_string(obj, message, info)
|
86
94
|
attrs = {
|
87
|
-
:
|
95
|
+
:message => message,
|
88
96
|
:size => obj.size,
|
89
97
|
:encoding => obj.encoding,
|
90
98
|
:ascii_only => obj.ascii_only?,
|
@@ -93,7 +101,7 @@ class DebugHelper
|
|
93
101
|
_show_item(obj.class.name, [obj], attrs, info)
|
94
102
|
end
|
95
103
|
|
96
|
-
def show_struct(obj,
|
104
|
+
def show_struct(obj, message, info)
|
97
105
|
content = {}
|
98
106
|
i = 0
|
99
107
|
obj.each_pair do |member|
|
@@ -103,15 +111,15 @@ class DebugHelper
|
|
103
111
|
i += 1
|
104
112
|
end
|
105
113
|
attrs = {
|
106
|
-
:
|
114
|
+
:message => message,
|
107
115
|
:size => obj.size,
|
108
116
|
}
|
109
117
|
_show_item(obj.class.name, content, attrs, info)
|
110
118
|
end
|
111
119
|
|
112
|
-
def show_symbol(obj,
|
120
|
+
def show_symbol(obj, message, info)
|
113
121
|
attrs = {
|
114
|
-
:
|
122
|
+
:message => message,
|
115
123
|
:size => obj.size,
|
116
124
|
:encoding => obj.encoding,
|
117
125
|
}
|
@@ -119,9 +127,9 @@ class DebugHelper
|
|
119
127
|
end
|
120
128
|
|
121
129
|
def _show_item(class_name, content, attrs, info)
|
122
|
-
|
123
|
-
unless
|
124
|
-
attrs[:
|
130
|
+
message = attrs[:message]
|
131
|
+
unless message.nil?
|
132
|
+
attrs[:message] = "'#{message}'"
|
125
133
|
end
|
126
134
|
label = label(class_name, attrs)
|
127
135
|
info.store(label, content)
|
@@ -137,18 +145,4 @@ class DebugHelper
|
|
137
145
|
"#{class_name} (#{attrs_s})"
|
138
146
|
end
|
139
147
|
|
140
|
-
# def respond_to!(obj, method)
|
141
|
-
# unless obj.respond_to?(method)
|
142
|
-
# message = "Instance of #{obj.class.name} does not respond to :#{method}"
|
143
|
-
# raise ArgumentError.new(message)
|
144
|
-
# end
|
145
|
-
# end
|
146
|
-
#
|
147
|
-
# def kind_of!(obj, klass)
|
148
|
-
# unless obj.kind_of?(klass)
|
149
|
-
# message = "Instance of #{obj.class.name} is not a kind of #{klass}"
|
150
|
-
# raise ArgumentError.new(message)
|
151
|
-
# end
|
152
|
-
# end
|
153
|
-
|
154
148
|
end
|
data/lib/debug_helper/version.rb
CHANGED
@@ -15,7 +15,7 @@ The output shows details of the array.
|
|
15
15
|
```show.yaml```:
|
16
16
|
```yaml
|
17
17
|
---
|
18
|
-
Array (
|
18
|
+
Array (message='My mixed array' size=3):
|
19
19
|
Element 0: Fixnum 0
|
20
20
|
Element 1:
|
21
21
|
String (size=3 encoding=UTF-8 ascii_only=true bytesize=3):
|
@@ -1,2 +1,2 @@
|
|
1
|
-
--- DateTime (
|
1
|
+
--- DateTime (message='My datetime') 2018-07-04T14:49:11-05:00
|
2
2
|
...
|
@@ -1,2 +1,2 @@
|
|
1
|
-
--- Range (
|
1
|
+
--- Range (message='My range') 0..9
|
2
2
|
...
|
@@ -1,2 +1,2 @@
|
|
1
|
-
--- Regexp (
|
1
|
+
--- Regexp (message='My regexp') (?-mix:foo)
|
2
2
|
...
|
@@ -18,7 +18,7 @@ The output shows details of the string.
|
|
18
18
|
```show.yaml```:
|
19
19
|
```yaml
|
20
20
|
---
|
21
|
-
String (
|
21
|
+
String (message='My multiline string' size=122 encoding=UTF-8 ascii_only=true bytesize=122):
|
22
22
|
- |
|
23
23
|
Lorem Ipsum dolor sit amet,consectetur adipisicing elit,
|
24
24
|
sed doeiusmod tempor incididunt ut laboreet dolore magna aliqua.
|
@@ -1,5 +1,5 @@
|
|
1
1
|
---
|
2
|
-
String (
|
2
|
+
String (message='My multiline string' size=122 encoding=UTF-8 ascii_only=true bytesize=122):
|
3
3
|
- |
|
4
4
|
Lorem Ipsum dolor sit amet,consectetur adipisicing elit,
|
5
5
|
sed doeiusmod tempor incididunt ut laboreet dolore magna aliqua.
|
@@ -15,6 +15,6 @@ The output shows details of the string.
|
|
15
15
|
```show.yaml```:
|
16
16
|
```yaml
|
17
17
|
---
|
18
|
-
String (
|
18
|
+
String (message='My simple string' size=11 encoding=UTF-8 ascii_only=true bytesize=11):
|
19
19
|
- Lorem ipsum
|
20
20
|
```
|
@@ -1,2 +1,2 @@
|
|
1
1
|
---
|
2
|
-
Symbol (
|
2
|
+
Symbol (message='My symbol' size=11 encoding=US-ASCII): :lorem_ipsum
|
data/markdown/readme/template.md
CHANGED
@@ -22,4 +22,23 @@ Others are treated as:
|
|
22
22
|
|
23
23
|
- [Object](#object)
|
24
24
|
|
25
|
+
## Class Method or Module Method?
|
26
|
+
|
27
|
+
Most examples in this documentation show use of the class method:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
require 'debug_helper'
|
31
|
+
DebugHelper.show(obj, message)
|
32
|
+
```
|
33
|
+
|
34
|
+
You can also choose to use the module method, ```putd``` (Thanks, [palkan](https://www.reddit.com/user/palkan)!), which looks a lot like ```puts```.
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
require 'debug_helper'
|
38
|
+
include DebugHelper::Putd
|
39
|
+
putd obj, message
|
40
|
+
```
|
41
|
+
|
42
|
+
Just be sure to ```include DebugHelper::Putd```.
|
43
|
+
|
25
44
|
@[:markdown](class_inclusions.md)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: debug_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- burdettelamar
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-07-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|