debug_me 1.0.3 → 1.0.4
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 +48 -16
- data/lib/debug_me.rb +11 -10
- data/lib/debug_me/version.rb +1 -1
- data/tests/world_view.rb +10 -8
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ee6256c053274e46630862e170317e97ea6bb0aa27394661473d0acd84fcb1d
|
4
|
+
data.tar.gz: 0e080550b9660678ec343b9650d89e8153e3e386913ac94d73f72c7eb70a87df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9479b7df27c05071f452eafd7a016ea34bfa42952217d1c1f81ec885e069ccb212f00c0339f3d918ccc2edcb215c030ff0a5808c61067cb48570a0c9bc91fd96
|
7
|
+
data.tar.gz: 29d34ee5dc5ec7534e0342a1187d8c15fc118bda3266c1ebcf37376090eb73b5327e22aace77db84052545b60170ce6c9433aa59dd88e024a6a8d6ffba7f0cd8
|
data/README.md
CHANGED
@@ -1,13 +1,21 @@
|
|
1
1
|
# DebugMe
|
2
2
|
|
3
|
-
|
3
|
+
A tool to print the labeled value of variables.
|
4
|
+
|
5
|
+
This thing is pretty old;but, so am I. For the gray
|
6
|
+
in our hair we still to the job.
|
7
|
+
|
8
|
+
There are much complex/comprehensive
|
4
9
|
ways of debugging in a complex application. But,
|
5
10
|
you know, I keep returning to this little method
|
6
11
|
time after time. I guess that marks me as a geezer.
|
7
12
|
|
8
|
-
A tool to print the labeled value of variables.
|
9
13
|
|
10
|
-
|
14
|
+
DebugMe::debug_me(){} works with local, instance and class variables.
|
15
|
+
|
16
|
+
## Recent Changes
|
17
|
+
|
18
|
+
* 1.0.4 Added :strftime to the options; changed the default format from decimal seconds since epic to something that os more easy comprehend on a clock.
|
11
19
|
|
12
20
|
## Installation
|
13
21
|
|
@@ -45,9 +53,9 @@ debug_me { [:this_one, :that_one, :that_other_one] } # prints default header and
|
|
45
53
|
# Each element of the array is 'eval'ed with the context binding of the caller
|
46
54
|
debug_me(){[ :my_var, 'my_complex_var_or_method[my_var]' ]}
|
47
55
|
|
48
|
-
debug_me(:
|
56
|
+
debug_me(header: false) {} # disables the printing of the header; prints all variables
|
49
57
|
|
50
|
-
debug_me(:
|
58
|
+
debug_me(tag: 'MyTag', :header => false) {} # disables header, sets different tag, prints all variables
|
51
59
|
|
52
60
|
debug_me('=== LOOK ===') {} # changes the tag and prints all variables with a header line
|
53
61
|
|
@@ -55,28 +63,52 @@ debug_me('=== LOOK ===') {:@foo} # changes the tag, prints a header line and a s
|
|
55
63
|
|
56
64
|
debug_me('=== LOOK ===') {:@@foo} # changes the tag, prints a header line and a specific class variable
|
57
65
|
|
58
|
-
debug_me(:
|
66
|
+
debug_me(ivar: false, cvar: false) {} # print only the local variables with the default tag and a header line
|
67
|
+
|
68
|
+
```
|
69
|
+
|
70
|
+
Most of the examples above use symbols to designate the variables that you want
|
71
|
+
to be shown with their name as a label. You can also use strings. With strings
|
72
|
+
you are not limited to just variables. Consider these examples:
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
debug_me {[ 'some_array.size', 'SomeDatabaseModel.count' ]}
|
76
|
+
|
77
|
+
# What a backtrace with your variables?
|
78
|
+
|
79
|
+
debug_me {[
|
80
|
+
:my_variable,
|
81
|
+
'some_hash.keys.reject{|k| k.to_s.start_with?('A')}',
|
82
|
+
'caller' ]} # yes, caller is a kernel method that will give a backtrace
|
83
|
+
|
84
|
+
# You can also get into trouble so be careful. The symbols and strings
|
85
|
+
# are evaluated in the context of the caller. Within the string any
|
86
|
+
# command or line of code can be given. SO DO NOT try to use
|
87
|
+
# something silly like debug_me{ 'system("rm -fr /")'}
|
59
88
|
|
60
89
|
```
|
61
90
|
|
62
91
|
## Default Options
|
63
92
|
|
64
|
-
The default options
|
93
|
+
The default options is a global constant `DebugMeDefaultOptions` that is outside of the `DebugMe` name space. I did that so that if you do `include DebugMe` to make access to the method easier you could still have the constant with a function specific name that would be outside of anything that you may have already coded in you program.
|
94
|
+
|
95
|
+
Notice that this constant is outside of the DebugMe's module namespace.
|
65
96
|
|
66
97
|
```
|
67
98
|
DebugMeDefaultOptions = {
|
68
|
-
tag:
|
69
|
-
time:
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
99
|
+
tag: 'DEBUG', # A tag to prepend to each output line
|
100
|
+
time: true, # Include a time-stamp in front of the tag
|
101
|
+
strftime: '%Y-%m-%d %H:%M:%S.%6N', # timestamp format
|
102
|
+
header: true, # Print a header string before printing the variables
|
103
|
+
lvar: true, # Include local variables
|
104
|
+
ivar: true, # Include instance variables in the output
|
105
|
+
cvar: true, # Include class variables in the output
|
106
|
+
cconst: true, # Include class constants
|
107
|
+
file: $stdout # The output file
|
76
108
|
}
|
77
109
|
```
|
78
110
|
|
79
|
-
If you want the output of the method to always
|
111
|
+
If you want the output of the method to always go to STDERR then do this:
|
80
112
|
|
81
113
|
```
|
82
114
|
require 'debug_me'
|
data/lib/debug_me.rb
CHANGED
@@ -2,14 +2,15 @@ require 'pp'
|
|
2
2
|
require_relative 'debug_me/version'
|
3
3
|
|
4
4
|
DebugMeDefaultOptions = {
|
5
|
-
tag:
|
6
|
-
time:
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
5
|
+
tag: 'DEBUG', # A tag to prepend to each output line
|
6
|
+
time: true, # Include a time-stamp in front of the tag
|
7
|
+
strftime: '%Y-%m-%d %H:%M:%S.%6N', # timestamp format
|
8
|
+
header: true, # Print a header string before printing the variables
|
9
|
+
lvar: true, # Include local variables
|
10
|
+
ivar: true, # Include instance variables in the output
|
11
|
+
cvar: true, # Include class variables in the output
|
12
|
+
cconst: true, # Include class constants
|
13
|
+
file: $stdout # The output file
|
13
14
|
}
|
14
15
|
|
15
16
|
module DebugMe
|
@@ -25,8 +26,8 @@ module DebugMe
|
|
25
26
|
|
26
27
|
f = options[:file]
|
27
28
|
s = ''
|
28
|
-
s +=
|
29
|
-
s += "
|
29
|
+
s += Time.now.strftime(options[:strftime])+' ' if options[:time]
|
30
|
+
s += "#{options[:tag]}"
|
30
31
|
wf = caller # where_from under 1.8.6 its a stack trace array under 1.8.7 is a string
|
31
32
|
wf = wf[0] if 'Array' == wf.class.to_s
|
32
33
|
|
data/lib/debug_me/version.rb
CHANGED
data/tests/world_view.rb
CHANGED
@@ -3,20 +3,23 @@ class WorldView
|
|
3
3
|
A = 1
|
4
4
|
B = 2
|
5
5
|
C = 3
|
6
|
+
|
6
7
|
def initialize
|
7
|
-
@a,@b,@c
|
8
|
-
@@d, @@e, @@f
|
8
|
+
@a,@b,@c = 1,2,3
|
9
|
+
@@d, @@e, @@f = 4,5,6
|
9
10
|
end
|
11
|
+
|
10
12
|
def everything
|
11
13
|
debug_me(
|
12
|
-
file:nil,
|
13
|
-
header:true,
|
14
|
-
lvar:
|
15
|
-
ivar:
|
16
|
-
cvar:
|
14
|
+
file: nil,
|
15
|
+
header: true,
|
16
|
+
lvar: true,
|
17
|
+
ivar: true,
|
18
|
+
cvar: true,
|
17
19
|
cconst: true
|
18
20
|
){}
|
19
21
|
end
|
22
|
+
|
20
23
|
def my_constants
|
21
24
|
debug_me(
|
22
25
|
file:nil,
|
@@ -26,6 +29,5 @@ class WorldView
|
|
26
29
|
cvar: false,
|
27
30
|
cconst: true
|
28
31
|
){}
|
29
|
-
|
30
32
|
end
|
31
33
|
end # class WorldView
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: debug_me
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dewayne VanHoozer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,8 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
80
80
|
- !ruby/object:Gem::Version
|
81
81
|
version: '0'
|
82
82
|
requirements: []
|
83
|
-
|
84
|
-
rubygems_version: 2.7.6
|
83
|
+
rubygems_version: 3.0.6
|
85
84
|
signing_key:
|
86
85
|
specification_version: 4
|
87
86
|
summary: A tool to print the labeled value of variables.
|