debug_helper 1.8.0 → 2.0.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.
Files changed (99) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/README.md +572 -314
  4. data/bin/console +14 -14
  5. data/lib/debug_helper/handler.rb +8 -2
  6. data/lib/debug_helper/version.rb +1 -1
  7. data/markdown/readme/Rakefile +2 -1
  8. data/markdown/readme/class_inclusions.md +1 -0
  9. data/markdown/readme/classes/array/circular/show.md +2 -2
  10. data/markdown/readme/classes/array/circular/show.yaml +2 -2
  11. data/markdown/readme/classes/array/mixed/show.md +9 -9
  12. data/markdown/readme/classes/array/mixed/show.yaml +9 -9
  13. data/markdown/readme/classes/array/nested/show.md +3 -3
  14. data/markdown/readme/classes/array/nested/show.yaml +3 -3
  15. data/markdown/readme/classes/array/simple/show.md +1 -1
  16. data/markdown/readme/classes/array/simple/show.yaml +1 -1
  17. data/markdown/readme/classes/custom/both/foo.rb +21 -0
  18. data/markdown/readme/classes/custom/both/foo_handler.rb +27 -0
  19. data/markdown/readme/classes/custom/both/show.md +100 -0
  20. data/markdown/readme/classes/custom/both/show.rb +5 -0
  21. data/markdown/readme/classes/custom/both/show.yaml +20 -0
  22. data/markdown/readme/classes/custom/both/template.md +19 -0
  23. data/markdown/readme/classes/custom/instance/foo.rb +13 -0
  24. data/markdown/readme/classes/custom/instance/foo_handler.rb +18 -0
  25. data/markdown/readme/classes/custom/instance/show.md +74 -0
  26. data/markdown/readme/classes/custom/instance/show.rb +5 -0
  27. data/markdown/readme/classes/custom/instance/show.yaml +11 -0
  28. data/markdown/readme/classes/custom/instance/template.md +19 -0
  29. data/markdown/readme/classes/custom/singleton/foo.rb +13 -0
  30. data/markdown/readme/classes/custom/singleton/foo_handler.rb +18 -0
  31. data/markdown/readme/classes/custom/singleton/show.md +74 -0
  32. data/markdown/readme/classes/custom/singleton/show.rb +5 -0
  33. data/markdown/readme/classes/custom/singleton/show.yaml +11 -0
  34. data/markdown/readme/classes/custom/singleton/template.md +19 -0
  35. data/markdown/readme/classes/custom/template.md +10 -0
  36. data/markdown/readme/classes/dir/simple/show.md +3 -3
  37. data/markdown/readme/classes/dir/simple/show.yaml +3 -3
  38. data/markdown/readme/classes/exception/simple/show.md +3 -3
  39. data/markdown/readme/classes/exception/simple/show.yaml +3 -3
  40. data/markdown/readme/classes/file/simple/show.md +17 -17
  41. data/markdown/readme/classes/file/simple/show.yaml +17 -17
  42. data/markdown/readme/classes/hash/circular/show.md +12 -12
  43. data/markdown/readme/classes/hash/circular/show.yaml +12 -12
  44. data/markdown/readme/classes/hash/mixed/show.md +20 -20
  45. data/markdown/readme/classes/hash/mixed/show.yaml +20 -20
  46. data/markdown/readme/classes/hash/nested/show.md +27 -27
  47. data/markdown/readme/classes/hash/nested/show.yaml +27 -27
  48. data/markdown/readme/classes/hash/simple/show.md +12 -12
  49. data/markdown/readme/classes/hash/simple/show.yaml +12 -12
  50. data/markdown/readme/classes/io/simple/show.md +4 -4
  51. data/markdown/readme/classes/io/simple/show.yaml +4 -4
  52. data/markdown/readme/classes/match_data/multiple_captures/show.md +5 -5
  53. data/markdown/readme/classes/match_data/multiple_captures/show.yaml +5 -5
  54. data/markdown/readme/classes/match_data/named_captures/show.md +5 -5
  55. data/markdown/readme/classes/match_data/named_captures/show.yaml +5 -5
  56. data/markdown/readme/classes/match_data/simple/show.md +5 -5
  57. data/markdown/readme/classes/match_data/simple/show.yaml +5 -5
  58. data/markdown/readme/classes/open_struct/circular/show.md +6 -6
  59. data/markdown/readme/classes/open_struct/circular/show.yaml +6 -6
  60. data/markdown/readme/classes/open_struct/mixed/show.md +17 -17
  61. data/markdown/readme/classes/open_struct/mixed/show.yaml +17 -17
  62. data/markdown/readme/classes/open_struct/nested/show.md +18 -18
  63. data/markdown/readme/classes/open_struct/nested/show.yaml +18 -18
  64. data/markdown/readme/classes/open_struct/simple/show.md +9 -9
  65. data/markdown/readme/classes/open_struct/simple/show.yaml +9 -9
  66. data/markdown/readme/classes/range/exclude_end/show.md +3 -3
  67. data/markdown/readme/classes/range/exclude_end/show.yaml +3 -3
  68. data/markdown/readme/classes/range/include_end/show.md +3 -3
  69. data/markdown/readme/classes/range/include_end/show.yaml +3 -3
  70. data/markdown/readme/classes/regexp/named_captures/show.md +5 -5
  71. data/markdown/readme/classes/regexp/named_captures/show.yaml +5 -5
  72. data/markdown/readme/classes/regexp/simple/show.md +5 -5
  73. data/markdown/readme/classes/regexp/simple/show.yaml +5 -5
  74. data/markdown/readme/classes/set/circular/show.md +2 -2
  75. data/markdown/readme/classes/set/circular/show.yaml +2 -2
  76. data/markdown/readme/classes/set/mixed/show.md +9 -9
  77. data/markdown/readme/classes/set/mixed/show.yaml +9 -9
  78. data/markdown/readme/classes/set/nested/show.md +3 -3
  79. data/markdown/readme/classes/set/nested/show.yaml +3 -3
  80. data/markdown/readme/classes/set/simple/show.md +1 -1
  81. data/markdown/readme/classes/set/simple/show.yaml +1 -1
  82. data/markdown/readme/classes/string/multiline/show.md +5 -5
  83. data/markdown/readme/classes/string/multiline/show.yaml +5 -5
  84. data/markdown/readme/classes/string/simple/show.md +5 -5
  85. data/markdown/readme/classes/string/simple/show.yaml +5 -5
  86. data/markdown/readme/classes/struct/circular/show.md +20 -20
  87. data/markdown/readme/classes/struct/circular/show.yaml +20 -20
  88. data/markdown/readme/classes/struct/mixed/show.md +18 -18
  89. data/markdown/readme/classes/struct/mixed/show.yaml +18 -18
  90. data/markdown/readme/classes/struct/nested/show.md +21 -21
  91. data/markdown/readme/classes/struct/nested/show.yaml +21 -21
  92. data/markdown/readme/classes/struct/simple/show.md +10 -10
  93. data/markdown/readme/classes/struct/simple/show.yaml +10 -10
  94. data/markdown/readme/classes/symbol/simple/show.md +3 -3
  95. data/markdown/readme/classes/symbol/simple/show.yaml +3 -3
  96. data/markdown/readme/options/depth/show.md +15 -15
  97. data/markdown/readme/options/depth/show.yaml +15 -15
  98. data/markdown/readme/template.md +11 -8
  99. metadata +21 -2
data/bin/console CHANGED
@@ -1,14 +1,14 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "debug_helper"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start(__FILE__)
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "debug_helper"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -29,10 +29,13 @@ class DebugHelper
29
29
  args = call_info
30
30
  if args.empty?
31
31
  value = obj.send(method)
32
+ key = "#{obj.class.name}##{method.to_s}"
32
33
  else
33
34
  value = obj.send(method, *args)
35
+ arglist = args.collect {|arg| arg.inspect}.join(', ')
36
+ key = "#{obj.class.name}##{method.to_s}(#{arglist})"
34
37
  end
35
- content.store(method.to_s, value)
38
+ content.store(key, value)
36
39
  end
37
40
  calls_for_class.each do |call_info|
38
41
  klass = Object.const_get(obj.class.name)
@@ -44,10 +47,13 @@ class DebugHelper
44
47
  args = call_info
45
48
  if args.empty?
46
49
  value = klass.send(method)
50
+ key = "#{klass}.#{method.to_s}"
47
51
  else
48
52
  value = klass.send(method, *args)
53
+ arglist = args.collect {|arg| arg.inspect}.join(', ')
54
+ key = "#{klass}.#{method.to_s}(#{arglist})"
49
55
  end
50
- content.store(method.to_s, value)
56
+ content.store(key, value)
51
57
  end
52
58
  if each_with_index?
53
59
  obj.each_with_index do |item, i|
@@ -1,3 +1,3 @@
1
1
  class DebugHelper
2
- VERSION = "1.8.0"
2
+ VERSION = "2.0.0"
3
3
  end
@@ -30,6 +30,7 @@ namespace :build do
30
30
  Struct
31
31
  Symbol
32
32
  Object
33
+ Custom
33
34
  /
34
35
  class_dir_names = []
35
36
  correct_dir_names = {
@@ -67,7 +68,7 @@ namespace :build do
67
68
  :open_struct => 'OpenStruct',
68
69
  }
69
70
  class_dir_names.each do |class_dir_name|
70
- next if class_dir_name == 'object'
71
+ next if %w/object custom/.include?(class_dir_name)
71
72
  if correct_class_names.include?(class_dir_name.to_sym)
72
73
  class_name = correct_class_names.fetch(class_dir_name.to_sym)
73
74
  else
@@ -13,3 +13,4 @@
13
13
  @[:markdown](classes/struct/template.md)
14
14
  @[:markdown](classes/symbol/template.md)
15
15
  @[:markdown](classes/object/template.md)
16
+ @[:markdown](classes/custom/template.md)
@@ -21,9 +21,9 @@ The circular reference is not followed.
21
21
  ```yaml
22
22
  ---
23
23
  Array (message='My circular arrays'):
24
- size: 1
24
+ Array#size: 1
25
25
  Element 0:
26
26
  Array:
27
- size: 1
27
+ Array#size: 1
28
28
  Element 0: Array [[[...]]]
29
29
  ```
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  Array (message='My circular arrays'):
3
- size: 1
3
+ Array#size: 1
4
4
  Element 0:
5
5
  Array:
6
- size: 1
6
+ Array#size: 1
7
7
  Element 0: Array [[[...]]]
@@ -16,18 +16,18 @@ The output shows details of the array.
16
16
  ```yaml
17
17
  ---
18
18
  Array (message='My mixed array'):
19
- size: 3
19
+ Array#size: 3
20
20
  Element 0: Fixnum 0
21
21
  Element 1:
22
22
  String:
23
- to_s: one
24
- size: 3
25
- encoding: !ruby/encoding UTF-8
26
- ascii_only?: true
27
- bytesize: 3
23
+ String#to_s: one
24
+ String#size: 3
25
+ String#encoding: !ruby/encoding UTF-8
26
+ String#ascii_only?: true
27
+ String#bytesize: 3
28
28
  Element 2:
29
29
  Symbol:
30
- to_s: two
31
- size: 3
32
- encoding: !ruby/encoding US-ASCII
30
+ Symbol#to_s: two
31
+ Symbol#size: 3
32
+ Symbol#encoding: !ruby/encoding US-ASCII
33
33
  ```
@@ -1,16 +1,16 @@
1
1
  ---
2
2
  Array (message='My mixed array'):
3
- size: 3
3
+ Array#size: 3
4
4
  Element 0: Fixnum 0
5
5
  Element 1:
6
6
  String:
7
- to_s: one
8
- size: 3
9
- encoding: !ruby/encoding UTF-8
10
- ascii_only?: true
11
- bytesize: 3
7
+ String#to_s: one
8
+ String#size: 3
9
+ String#encoding: !ruby/encoding UTF-8
10
+ String#ascii_only?: true
11
+ String#bytesize: 3
12
12
  Element 2:
13
13
  Symbol:
14
- to_s: two
15
- size: 3
16
- encoding: !ruby/encoding US-ASCII
14
+ Symbol#to_s: two
15
+ Symbol#size: 3
16
+ Symbol#encoding: !ruby/encoding US-ASCII
@@ -16,16 +16,16 @@ The output shows details of the arrays.
16
16
  ```yaml
17
17
  ---
18
18
  Array (message='My nested arrays'):
19
- size: 3
19
+ Array#size: 3
20
20
  Element 0: Fixnum 0
21
21
  Element 1:
22
22
  Array:
23
- size: 2
23
+ Array#size: 2
24
24
  Element 0: Fixnum 1
25
25
  Element 1: Fixnum 2
26
26
  Element 2:
27
27
  Array:
28
- size: 2
28
+ Array#size: 2
29
29
  Element 0: Fixnum 3
30
30
  Element 1: Fixnum 4
31
31
  ```
@@ -1,14 +1,14 @@
1
1
  ---
2
2
  Array (message='My nested arrays'):
3
- size: 3
3
+ Array#size: 3
4
4
  Element 0: Fixnum 0
5
5
  Element 1:
6
6
  Array:
7
- size: 2
7
+ Array#size: 2
8
8
  Element 0: Fixnum 1
9
9
  Element 1: Fixnum 2
10
10
  Element 2:
11
11
  Array:
12
- size: 2
12
+ Array#size: 2
13
13
  Element 0: Fixnum 3
14
14
  Element 1: Fixnum 4
@@ -16,7 +16,7 @@ The output shows details of the array.
16
16
  ```yaml
17
17
  ---
18
18
  Array (message='My simple array'):
19
- size: 3
19
+ Array#size: 3
20
20
  Element 0: Fixnum 5
21
21
  Element 1: Fixnum 10
22
22
  Element 2: Fixnum 15
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  Array (message='My simple array'):
3
- size: 3
3
+ Array#size: 3
4
4
  Element 0: Fixnum 5
5
5
  Element 1: Fixnum 10
6
6
  Element 2: Fixnum 15
@@ -0,0 +1,21 @@
1
+ require 'debug_helper'
2
+
3
+ class Foo
4
+
5
+ def my_array
6
+ %w/foo bar baz/
7
+ end
8
+
9
+ def my_hash
10
+ {:a => 0, :b => 1}
11
+ end
12
+
13
+ def self.my_array
14
+ %w/bat bam bad/
15
+ end
16
+
17
+ def self.my_hash
18
+ {:c => 2, :d => 3}
19
+ end
20
+
21
+ end
@@ -0,0 +1,27 @@
1
+ require 'debug_helper'
2
+
3
+ class DebugHelper
4
+
5
+ class FooHandler < Handler
6
+
7
+ def calls_for_instance
8
+ [
9
+ [:my_array],
10
+ [:my_hash],
11
+ [:respond_to?, :your_array],
12
+ [:respond_to?, :your_hash],
13
+ ]
14
+ end
15
+
16
+ def calls_for_class
17
+ [
18
+ [:my_array],
19
+ [:my_hash],
20
+ [:respond_to?, :your_array],
21
+ [:respond_to?, :your_hash],
22
+ ]
23
+ end
24
+
25
+ end
26
+
27
+ end
@@ -0,0 +1,100 @@
1
+ #### Instance and Singleton Methods
2
+
3
+ This example shows a custom handler that explicates via both kinds of methods.
4
+
5
+ Here's a class ```Foo``` that has instance methods and singleton methods:
6
+
7
+ ```foo.rb```:
8
+ ```ruby
9
+ require 'debug_helper'
10
+
11
+ class Foo
12
+
13
+ def my_array
14
+ %w/foo bar baz/
15
+ end
16
+
17
+ def my_hash
18
+ {:a => 0, :b => 1}
19
+ end
20
+
21
+ def self.my_array
22
+ %w/bat bam bad/
23
+ end
24
+
25
+ def self.my_hash
26
+ {:c => 2, :d => 3}
27
+ end
28
+
29
+ end
30
+ ```
31
+
32
+ Here's its custom debug handler class ```FooHandler```.
33
+
34
+ ```foo_handler.rb```:
35
+ ```ruby
36
+ require 'debug_helper'
37
+
38
+ class DebugHelper
39
+
40
+ class FooHandler < Handler
41
+
42
+ def calls_for_instance
43
+ [
44
+ [:my_array],
45
+ [:my_hash],
46
+ [:respond_to?, :your_array],
47
+ [:respond_to?, :your_hash],
48
+ ]
49
+ end
50
+
51
+ def calls_for_class
52
+ [
53
+ [:my_array],
54
+ [:my_hash],
55
+ [:respond_to?, :your_array],
56
+ [:respond_to?, :your_hash],
57
+ ]
58
+ end
59
+
60
+ end
61
+
62
+ end
63
+ ```
64
+
65
+ Here's a program that uses the custom handler.
66
+
67
+ ```show.rb```:
68
+ ```ruby
69
+ require 'debug_helper'
70
+ require_relative 'foo'
71
+ require_relative 'foo_handler'
72
+
73
+ DebugHelper.show(Foo.new, 'My class Foo')
74
+ ```
75
+
76
+ The output shows details of the object.
77
+
78
+ ```show.yaml```:
79
+ ```yaml
80
+ ---
81
+ Foo (message='My class Foo'):
82
+ Foo#my_array:
83
+ - foo
84
+ - bar
85
+ - baz
86
+ Foo#my_hash:
87
+ :a: 0
88
+ :b: 1
89
+ Foo#respond_to?(:your_array): false
90
+ Foo#respond_to?(:your_hash): false
91
+ Foo.my_array:
92
+ - bat
93
+ - bam
94
+ - bad
95
+ Foo.my_hash:
96
+ :c: 2
97
+ :d: 3
98
+ Foo.respond_to?(:your_array): false
99
+ Foo.respond_to?(:your_hash): false
100
+ ```
@@ -0,0 +1,5 @@
1
+ require 'debug_helper'
2
+ require_relative 'foo'
3
+ require_relative 'foo_handler'
4
+
5
+ DebugHelper.show(Foo.new, 'My class Foo')
@@ -0,0 +1,20 @@
1
+ ---
2
+ Foo (message='My class Foo'):
3
+ Foo#my_array:
4
+ - foo
5
+ - bar
6
+ - baz
7
+ Foo#my_hash:
8
+ :a: 0
9
+ :b: 1
10
+ Foo#respond_to?(:your_array): false
11
+ Foo#respond_to?(:your_hash): false
12
+ Foo.my_array:
13
+ - bat
14
+ - bam
15
+ - bad
16
+ Foo.my_hash:
17
+ :c: 2
18
+ :d: 3
19
+ Foo.respond_to?(:your_array): false
20
+ Foo.respond_to?(:your_hash): false
@@ -0,0 +1,19 @@
1
+ #### Instance and Singleton Methods
2
+
3
+ This example shows a custom handler that explicates via both kinds of methods.
4
+
5
+ Here's a class ```Foo``` that has instance methods and singleton methods:
6
+
7
+ @[ruby](foo.rb)
8
+
9
+ Here's its custom debug handler class ```FooHandler```.
10
+
11
+ @[ruby](foo_handler.rb)
12
+
13
+ Here's a program that uses the custom handler.
14
+
15
+ @[ruby](show.rb)
16
+
17
+ The output shows details of the object.
18
+
19
+ @[yaml](show.yaml)
@@ -0,0 +1,13 @@
1
+ require 'debug_helper'
2
+
3
+ class Foo
4
+
5
+ def my_array
6
+ %w/foo bar baz/
7
+ end
8
+
9
+ def my_hash
10
+ {:a => 0, :b => 1}
11
+ end
12
+
13
+ end