debug_me 1.1.1 → 1.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 406de0bd607687bab5c7a46e6dfde187353c24dfaf0800e2b5c0cd9223a8faf8
4
- data.tar.gz: f3f85a306a6455e2e699558a41e7d78b7eded223f862ce34c8ee02e3f487a268
3
+ metadata.gz: f108fdf3be1ba9af408d444553e0f3f20629e63bd7a845d07a36d5b0930a1e2c
4
+ data.tar.gz: f7ac4bb71cf494b5a9d7673eddf4317a559c8abbd2c30e9aba0c7d5e63102f7e
5
5
  SHA512:
6
- metadata.gz: 7ae3bf7696135d7d42ee5c0894a0d8d57b1ee2e93ce1236622b17f882ceaa67b9b0ac8769a2be01dd3291947363d5323c04138e2c5fdf141d0f1efcc20aa3b4c
7
- data.tar.gz: 3d756257d84c6e72edaf7debfb6d7100fa8a7f43a81254cbcdbdf204cf8ff118c163a7136a92be076b017b2cd411fc1075f596e140a361036c41f0ed88e2e505
6
+ metadata.gz: cf266b72ecaeb9878c74a3221397f5bb2f098b521f5bdf42bffe24dd974f6e30f1cc785732240ec9379c6f25cdebcb18926896335e4129d6bb9bcd21d92c294a
7
+ data.tar.gz: 8826d3cd49c6661c93f36a48ff3fc42fb71282183e8cef56f8068ee560591d7f24b5145b126b239ede09d91450a5664aff18eefb36eae03ac46e27a51d8a2177
data/CHANGELOG.md ADDED
@@ -0,0 +1,80 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [1.1.2] - 2025-01-13
11
+
12
+ ### Changed
13
+ - Updated test syntax for Minitest 6 compatibility
14
+ - Improved gemspec with proper metadata and MIT license
15
+ - Enhanced README with prominent security warning about `eval()` usage
16
+ - Enhanced README with dedicated section explaining `$DEBUG_ME` global flag usage
17
+ - Enhanced README with visual header image and classic debugging technique description
18
+ - `$DEBUG_ME` now initializes from `ENV['DEBUG_ME']` environment variable automatically
19
+
20
+ ### Fixed
21
+ - Fixed class variable tests by moving them to proper class context
22
+ - Fixed type checking to use idiomatic `is_a?(Hash)` instead of string comparison
23
+ - Fixed typos in test descriptions ("multible" → "multiple")
24
+ - Removed commented-out dead code
25
+
26
+ ### Added
27
+ - Added visual header image (debug_me.jpg) to README
28
+ - Added `DEBUG_ME_MAX_BACKTRACE` constant for magic number
29
+ - Added missing development dependencies (`amazing_print`, `minitest`)
30
+ - Added `required_ruby_version` to gemspec
31
+ - Added CHANGELOG.md file
32
+ - Added comprehensive test suite for `$DEBUG_ME` global flag (7 tests)
33
+ - Added documentation for `$DEBUG_ME` with Rails and non-Rails examples
34
+ - Added `ENV['DEBUG_ME']` environment variable support for controlling debug output
35
+ - Added environment variable tests covering all boolean value representations
36
+ - Added production deployment examples (Docker, Heroku, systemd) to README
37
+
38
+ ## [1.1.1] - 2020-04-27
39
+
40
+ ### Added
41
+ - Added global constant `$DEBUG_ME` as a boolean (default: true)
42
+ - When `$DEBUG_ME` is false, the `debug_me` method does nothing
43
+
44
+ ## [1.1.0] - 2020-04-27
45
+
46
+ ### Changed
47
+ - Changed output formatting with respect to the use of levels option
48
+
49
+ ### Added
50
+ - Added `:backtrace` option for full backtrace display
51
+
52
+ ## [1.0.6] - 2020-04-26
53
+
54
+ ### Added
55
+ - Added support for variable backtrace length via the `:levels` option
56
+
57
+ ## [1.0.5] - 2020-04-25
58
+
59
+ ### Added
60
+ - Added support for an instance of a Logger class (e.g., Rails.logger)
61
+
62
+ ## [1.0.4] - 2020-04-24
63
+
64
+ ### Added
65
+ - Added `:strftime` option for customizable timestamp formatting
66
+
67
+ ### Changed
68
+ - Changed default timestamp format from decimal seconds since epoch to human-readable clock format (`%Y-%m-%d %H:%M:%S.%6N`)
69
+
70
+ ## Earlier Versions
71
+
72
+ See git history for changes in versions prior to 1.0.4.
73
+
74
+ [Unreleased]: https://github.com/MadBomber/debug_me/compare/v1.1.2...HEAD
75
+ [1.1.2]: https://github.com/MadBomber/debug_me/compare/v1.1.1...v1.1.2
76
+ [1.1.1]: https://github.com/MadBomber/debug_me/releases/tag/v1.1.1
77
+ [1.1.0]: https://github.com/MadBomber/debug_me/releases/tag/v1.1.0
78
+ [1.0.6]: https://github.com/MadBomber/debug_me/releases/tag/v1.0.6
79
+ [1.0.5]: https://github.com/MadBomber/debug_me/releases/tag/v1.0.5
80
+ [1.0.4]: https://github.com/MadBomber/debug_me/releases/tag/v1.0.4
data/README.md CHANGED
@@ -1,41 +1,56 @@
1
1
  # DebugMe
2
2
 
3
- A tool to print the labeled value of variables.
3
+ <table>
4
+ <tr>
5
+ <td width="30%">
6
+ <img src="debug_me.jpg" alt="DebugMe Logo"/>
7
+ </td>
8
+ <td width="70%">
4
9
 
5
- This thing is pretty old; but, so am I. Even with the gray
6
- in our hair we still do the job.
10
+ ## A Classic Debugging Technique That Never Gets Old
7
11
 
8
- There are much more complex/comprehensive
9
- ways of debugging in a complex application. But,
10
- you know, I keep returning to this little method
11
- time after time. I guess that marks me as a geezer.
12
+ Printing labeled variable values to STDOUT is one of the oldest and most fundamental debugging techniques in computer science. From the earliest days of programming, developers have relied on simple output statements to understand what their code is doing. While modern debuggers offer sophisticated features like breakpoints and step-through execution, there's something elegantly simple and universally effective about printing variables to see their values in real-time.
12
13
 
14
+ **DebugMe** embraces this time-tested approach, making it effortless to inspect local, instance, and class variables with clearly labeled output. Sometimes the old ways are the best ways.
13
15
 
14
- DebugMe::debug_me(){} works with local, instance and class variables.
16
+ </td>
17
+ </tr>
18
+ </table>
19
+
20
+ ---
15
21
 
16
- ## Recent Changes
22
+ ## Quick Start
23
+
24
+ ```ruby
25
+ gem install debug_me
26
+
27
+ require 'debug_me'
28
+ include DebugMe
29
+
30
+ my_variable = 42
31
+
32
+ debug_me { :my_variable } # Use a Symbol for the variable name
33
+
34
+ # or if you have several variables you want to see ...
35
+ debug_me { %i[ var1 var2 var3 var4 ]}
36
+ ```
37
+
38
+ DebugMe::debug_me(){} works with local, instance and class variables.
17
39
 
18
- * 1.1.1 Added global constant $DEBUG_ME as a boolean; default is true. when false the debug_me method does nothing.
19
- * 1.1.0 Changes the output formatting w/r/t the use of levels option; add :backtrace option for full backtrace
20
- * 1.0.6 Added support for variable backtrack length via the :levels option
21
- * 1.0.5 Added support for an instance of a Logger class.
22
- * 1.0.4 Added :strftime to the options; changed the default format from decimal seconds since epic to something that is more easy comprehend on a clock.
23
40
 
24
41
  ## Installation
25
42
 
26
43
  Add this line to your application's Gemfile:
27
44
 
28
45
  ```ruby
29
- gem 'debug_me'
46
+ bundle add 'debug_me'
30
47
  ```
31
48
 
32
- And then execute:
49
+ Or install it yourself:
33
50
 
34
- $ bundle
35
-
36
- Or install it yourself as:
37
-
38
- $ gem install debug_me
51
+ ```ruby
52
+ gem install debug_me
53
+ ```
39
54
 
40
55
  ## Examples Usage
41
56
 
@@ -56,7 +71,7 @@ debug_me {} # prints the default header and __ALL__ variables
56
71
 
57
72
  debug_me {:just_this_variable} # prints the default header and the value of only one specific variable
58
73
 
59
- debug_me { [:this_one, :that_one, :that_other_one] } # prints default header and three specific variables
74
+ debug_me { %i[ this_one that_one that_other_one ]} # prints default header and three specific variables
60
75
 
61
76
  # Use an array of symbols and strings to pass multiple variables for output
62
77
  # Each element of the array is 'eval'ed with the context binding of the caller
@@ -97,6 +112,118 @@ debug_me {[
97
112
 
98
113
  ```
99
114
 
115
+ ## Security Warning
116
+
117
+ **IMPORTANT:** `debug_me` uses `eval()` to evaluate the symbols and strings you pass to it in the context of the caller. This provides powerful flexibility but comes with significant security implications:
118
+
119
+ - **Never** pass untrusted input to `debug_me`
120
+ - **Never** use `debug_me` with user-supplied data or parameters
121
+ - Only use `debug_me` during development and testing
122
+ - Remove or disable `debug_me` calls in production code (use `$DEBUG_ME = false`)
123
+
124
+ The ability to execute arbitrary code is by design for debugging flexibility, but it means any string passed to `debug_me` will be evaluated as Ruby code. Treat this tool with the same caution you would any `eval()` statement.
125
+
126
+ For production environments, consider using a proper logging framework with structured logging instead of `debug_me`.
127
+
128
+ ## Disabling Debug Output with $DEBUG_ME
129
+
130
+ The `$DEBUG_ME` global variable provides a convenient way to enable or disable all `debug_me` output throughout your application without removing the code. This is particularly useful for QA environments.
131
+
132
+ ### Environment Variable Control (Recommended)
133
+
134
+ The `DEBUG_ME` environment variable is automatically detected when the gem is loaded. This is the **recommended approach** for controlling debug output across environments without code changes.
135
+
136
+ ```bash
137
+ # Disable debug output (QA)
138
+ export DEBUG_ME=false
139
+
140
+ # Enable debug output (development)
141
+ export DEBUG_ME=true
142
+
143
+ # Or set inline when running your app
144
+ DEBUG_ME=false bundle exec rails server
145
+ ```
146
+
147
+ **Supported values:**
148
+ - **Truthy** (enables output): `true`, `yes`, `1`, `on`, or any other value
149
+ - **Falsy** (disables output): `false`, `no`, `0`, `off`, or empty string
150
+ - **Not set**: Defaults to `true` (enabled)
151
+
152
+ ### Runtime Control
153
+
154
+ You can also control `$DEBUG_ME` programmatically at runtime:
155
+
156
+ ```ruby
157
+ # Enable debug output (default)
158
+ $DEBUG_ME = true
159
+
160
+ # Disable all debug_me output
161
+ $DEBUG_ME = false
162
+ ```
163
+
164
+ When `$DEBUG_ME` is set to `false`:
165
+ - All `debug_me` calls return `nil` immediately
166
+ - No output is produced (even with custom file or logger options)
167
+ - **The block is not evaluated**, so there's zero performance overhead
168
+
169
+ ### Production Setup Examples
170
+
171
+ **Docker/Container deployment:**
172
+ ```dockerfile
173
+ # Dockerfile
174
+ ENV DEBUG_ME=false
175
+ ```
176
+
177
+ **Systemd service:**
178
+ ```ini
179
+ [Service]
180
+ Environment="DEBUG_ME=false"
181
+ ```
182
+
183
+ **Heroku:**
184
+ ```bash
185
+ heroku config:set DEBUG_ME=false
186
+ ```
187
+
188
+ **For Rails with fallback** (only if ENV not set):
189
+
190
+ ```ruby
191
+ # config/initializers/debug_me.rb
192
+ require 'debug_me'
193
+
194
+ # Override only if not already set by environment
195
+ $DEBUG_ME = Rails.env.development? || Rails.env.test? unless ENV.key?('DEBUG_ME')
196
+ ```
197
+
198
+ ### Benefits
199
+
200
+ - **Leave debug code in place**: No need to remove `debug_me` calls before deployment
201
+ - **Zero overhead**: When disabled, blocks aren't evaluated, so no performance impact
202
+ - **Easy toggling**: Can enable debugging in production temporarily if needed
203
+ - **Security**: Prevents accidental debug output exposure in production
204
+
205
+ ### Example
206
+
207
+ ```ruby
208
+ # Your code with debug_me calls
209
+ def process_data(items)
210
+ debug_me { :items } # Only outputs in development/test
211
+
212
+ result = items.map do |item|
213
+ debug_me { :item } # Only outputs in development/test
214
+ transform(item)
215
+ end
216
+
217
+ debug_me { :result } # Only outputs in development/test
218
+ result
219
+ end
220
+
221
+ # In production with $DEBUG_ME = false:
222
+ # - No output produced
223
+ # - No performance overhead
224
+ # - Code works normally
225
+ ```
226
+
100
227
  ## Default Options
101
228
 
102
229
  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.
@@ -131,7 +258,6 @@ If you want the `debug_me` output to go to a real file:
131
258
 
132
259
  ```ruby
133
260
  DebugMeDefaultOptions[:file] = File.open('debug_me.log', 'w')
134
-
135
261
  ```
136
262
 
137
263
  ## Using a Logger class instance
@@ -139,7 +265,6 @@ DebugMeDefaultOptions[:file] = File.open('debug_me.log', 'w')
139
265
  If you are working in Rails and want all the `debug_me` output to go to the Rails.logger its as easy as:
140
266
  ```ruby
141
267
  DebugMeDefaultOptions[:logger] = Rails.logger
142
-
143
268
  ```
144
269
 
145
270
  Or while working in rails you only want to add a marker to the Rails.logger do this:
@@ -147,7 +272,7 @@ Or while working in rails you only want to add a marker to the Rails.logger do t
147
272
  debug_me(logger: Rails.logger, tag: 'Hello World')
148
273
  ```
149
274
 
150
- If you are working in Rails and want to use both the standard `debug_me` functions and occassionally put stuff into the Rails.logger but do not want to always remember the option settings then do something line this in a `config/initializers/aaaaa_debug_me.rb` file:
275
+ If you are working in Rails and want to use both the standard `debug_me` functions and put stuff into the Rails.logger but do not want to always remember the option settings then do something line this in a `config/initializers/aaaaa_debug_me.rb` file:
151
276
 
152
277
  ```ruby
153
278
  # config/initializers/aaaaa_debug_me.rb
@@ -202,9 +327,9 @@ The rest of the default options are obvious.
202
327
 
203
328
  You can always over-ride the default options on a case by case basis like this:
204
329
 
205
- ```
330
+ ```ruby
206
331
  debug_me {...}
207
- ...
332
+ # ...
208
333
  debug_me(header: false){...}
209
334
  ```
210
335
 
data/debug_me.gemspec CHANGED
@@ -14,7 +14,16 @@ ways of debugging in a complex application. But,
14
14
  you know, I keep returning to this little method
15
15
  time after time. I guess that marks me as a geezer.'
16
16
  spec.homepage = 'http://github.com/MadBomber/debug_me'
17
- spec.license = 'You want it, its yours'
17
+ spec.license = 'MIT'
18
+
19
+ spec.required_ruby_version = '>= 2.3.0'
20
+
21
+ spec.metadata = {
22
+ 'homepage_uri' => 'https://github.com/MadBomber/debug_me',
23
+ 'source_code_uri' => 'https://github.com/MadBomber/debug_me',
24
+ 'bug_tracker_uri' => 'https://github.com/MadBomber/debug_me/issues',
25
+ 'changelog_uri' => 'https://github.com/MadBomber/debug_me/blob/master/CHANGELOG.md'
26
+ }
18
27
 
19
28
  spec.files = `git ls-files -z`.split("\x0")
20
29
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
@@ -23,4 +32,6 @@ time after time. I guess that marks me as a geezer.'
23
32
 
24
33
  spec.add_development_dependency 'bundler'
25
34
  spec.add_development_dependency 'rake'
35
+ spec.add_development_dependency 'amazing_print'
36
+ spec.add_development_dependency 'minitest', '~> 5.0'
26
37
  end
data/debug_me.jpg ADDED
Binary file
@@ -4,5 +4,5 @@ module DebugMe
4
4
  # to get direct access to the debug_me method without
5
5
  # polluting your code with an object name that is so
6
6
  # common.
7
- DEBUG_ME_VERSION = '1.1.1'
7
+ DEBUG_ME_VERSION = '1.1.2'
8
8
  end
data/lib/debug_me.rb CHANGED
@@ -1,7 +1,14 @@
1
1
  require 'pp'
2
2
  require_relative 'debug_me/version'
3
3
 
4
- $DEBUG_ME = true
4
+ # Initialize $DEBUG_ME from environment variable or default to true
5
+ # Supports common boolean representations: true/false, yes/no, 1/0, on/off
6
+ if ENV.key?('DEBUG_ME')
7
+ env_value = ENV['DEBUG_ME'].to_s.downcase
8
+ $DEBUG_ME = !['false', 'no', '0', 'off', ''].include?(env_value)
9
+ else
10
+ $DEBUG_ME = true
11
+ end
5
12
 
6
13
  DebugMeDefaultOptions = {
7
14
  tag: 'DEBUG', # A tag to prepend to each output line
@@ -20,11 +27,14 @@ DebugMeDefaultOptions = {
20
27
  file: $stdout # The output file
21
28
  }
22
29
 
30
+ # Maximum number of backtrace entries to show
31
+ DEBUG_ME_MAX_BACKTRACE = 10000
32
+
23
33
  module DebugMe
24
34
  def debug_me(options = {}, &block)
25
35
  return unless $DEBUG_ME
26
36
 
27
- if 'Hash' == options.class.to_s
37
+ if options.is_a?(Hash)
28
38
  options = DebugMeDefaultOptions.merge(options)
29
39
  else
30
40
  options = DebugMeDefaultOptions.merge(tag: options)
@@ -76,7 +86,7 @@ module DebugMe
76
86
  block_value.each do |v|
77
87
 
78
88
  ev = if 'backtrace' == v
79
- bt_out.size > 0 ? bt_out : bt[1..10000]
89
+ bt_out.size > 0 ? bt_out : bt[1..DEBUG_ME_MAX_BACKTRACE]
80
90
  else
81
91
  eval("defined?(#{v})",block.binding).nil? ? '<undefined>' : eval(v, block.binding)
82
92
  end
@@ -96,8 +106,4 @@ module DebugMe
96
106
 
97
107
  return out_string
98
108
  end ## def debug_me( options={}, &block )
99
-
100
- # def log_me(msg, opts={})
101
- # debug_me({tag: msg, header: false}.merge(opts))
102
- # end
103
109
  end # module DebugMe
@@ -77,16 +77,16 @@ describe DebugMe do
77
77
  a,b,c = 1,2,3
78
78
  out_string = debug_me(file:nil,header:false){:a}
79
79
  assert out_string.include? "a -=> #{a}"
80
- out_string.split("\n").size.must_equal 1
80
+ _(out_string.split("\n").size).must_equal 1
81
81
  end
82
82
 
83
- it "supports multible variables" do
83
+ it "supports multiple variables" do
84
84
  a,b,c = 1,2,3
85
85
  out_string = debug_me(file:nil,header:false){[:a, :b, :c]}
86
86
  assert out_string.include? "a -=> #{a}"
87
87
  assert out_string.include? "b -=> #{b}"
88
88
  assert out_string.include? "c -=> #{c}"
89
- out_string.split("\n").size.must_equal 3
89
+ _(out_string.split("\n").size).must_equal 3
90
90
  end
91
91
 
92
92
  it "shows all local variables" do
@@ -104,7 +104,7 @@ describe DebugMe do
104
104
  assert out_string.include? "c -=> #{c}"
105
105
  assert out_string.include? "out_string -=> "
106
106
 
107
- out_string.split("\n").size.must_equal 4
107
+ _(out_string.split("\n").size).must_equal 4
108
108
  end
109
109
 
110
110
  end # describe "works with local variable" do
@@ -115,16 +115,16 @@ describe DebugMe do
115
115
  @a,@b,@c = 1,2,3
116
116
  out_string = debug_me(file:nil,header:false){:@a}
117
117
  assert out_string.include? "@a -=> #{@a}"
118
- out_string.split("\n").size.must_equal 1
118
+ _(out_string.split("\n").size).must_equal 1
119
119
  end
120
120
 
121
- it "supports multible variables" do
121
+ it "supports multiple variables" do
122
122
  @a,@b,@c = 1,2,3
123
123
  out_string = debug_me(file:nil,header:false){[:@a, :@b, :@c]}
124
124
  assert out_string.include? "@a -=> #{@a}"
125
125
  assert out_string.include? "@b -=> #{@b}"
126
126
  assert out_string.include? "@c -=> #{@c}"
127
- out_string.split("\n").size.must_equal 3
127
+ _(out_string.split("\n").size).must_equal 3
128
128
  end
129
129
 
130
130
  it "shows all instance variables" do
@@ -141,8 +141,8 @@ describe DebugMe do
141
141
  assert out_string.include? "@b -=> #{@b}"
142
142
  assert out_string.include? "@c -=> #{@c}"
143
143
 
144
- out_string.include?("out_string -=> ").must_equal false
145
- out_string.split("\n").size.must_equal instance_variables.size
144
+ _(out_string.include?("out_string -=> ")).must_equal false
145
+ _(out_string.split("\n").size).must_equal instance_variables.size
146
146
  end
147
147
 
148
148
  end # describe "works with instance variable" do
@@ -151,41 +151,33 @@ describe DebugMe do
151
151
  describe "works with class variable" do
152
152
 
153
153
  it "supports a single variable" do
154
- @@a,@@b,@@c = 1,2,3
155
- out_string = debug_me(file:nil,header:false){:@@a}
156
- assert out_string.include? "@@a -=> #{@@a}"
157
- out_string.split("\n").size.must_equal 1
154
+ my_world_view = WorldView.new
155
+ out_string = my_world_view.test_single_class_var
156
+ assert out_string.include? "@@d -=> 4"
157
+ _(out_string.split("\n").size).must_equal 1
158
158
  end
159
159
 
160
- it "supports multible variables" do
161
- @@a,@@b,@@c = 1,2,3
162
- out_string = debug_me(file:nil,header:false){[:@@a, :@@b, :@@c]}
163
- assert out_string.include? "@@a -=> #{@@a}"
164
- assert out_string.include? "@@b -=> #{@@b}"
165
- assert out_string.include? "@@c -=> #{@@c}"
166
- out_string.split("\n").size.must_equal 3
160
+ it "supports multiple variables" do
161
+ my_world_view = WorldView.new
162
+ out_string = my_world_view.test_multiple_class_vars
163
+ assert out_string.include? "@@d -=> 4"
164
+ assert out_string.include? "@@e -=> 5"
165
+ assert out_string.include? "@@f -=> 6"
166
+ _(out_string.split("\n").size).must_equal 3
167
167
  end
168
168
 
169
169
  it "shows all class variables" do
170
- @@a,@@b,@@c = 1,2,3
171
- @d = 4
172
- out_string = debug_me(
173
- file:nil,
174
- header:false,
175
- lvar: false,
176
- ivar: false,
177
- cvar: true,
178
- cconst: false
179
- ){}
170
+ my_world_view = WorldView.new
171
+ out_string = my_world_view.test_all_class_vars
180
172
 
181
- assert out_string.include? "@@a -=> #{@@a}"
182
- assert out_string.include? "@@b -=> #{@@b}"
183
- assert out_string.include? "@@c -=> #{@@c}"
173
+ assert out_string.include? "@@d -=> 4"
174
+ assert out_string.include? "@@e -=> 5"
175
+ assert out_string.include? "@@f -=> 6"
184
176
 
185
- out_string.include?("out_string -=> ").must_equal false
186
- out_string.include?("@d -=> ").must_equal false
177
+ _(out_string.include?("out_string -=> ")).must_equal false
178
+ _(out_string.include?("@a -=> ")).must_equal false
187
179
 
188
- out_string.split("\n").size.must_equal self.class.class_variables.size
180
+ _(out_string.split("\n").size).must_equal WorldView.class_variables.size
189
181
  end
190
182
 
191
183
  end # describe "works with class variable" do
@@ -197,16 +189,16 @@ describe DebugMe do
197
189
  A,B,C = 1,2,3
198
190
  out_string = debug_me(file:nil,header:false){:A}
199
191
  assert out_string.include? "A -=> #{A}"
200
- out_string.split("\n").size.must_equal 1
192
+ _(out_string.split("\n").size).must_equal 1
201
193
  end
202
194
 
203
- it "supports multible CONSTANTS" do
195
+ it "supports multiple CONSTANTS" do
204
196
  A,B,C = 1,2,3
205
197
  out_string = debug_me(file:nil,header:false){[:A, :B, :C]}
206
198
  assert out_string.include? "A -=> #{A}"
207
199
  assert out_string.include? "B -=> #{B}"
208
200
  assert out_string.include? "C -=> #{C}"
209
- out_string.split("\n").size.must_equal 3
201
+ _(out_string.split("\n").size).must_equal 3
210
202
  end
211
203
 
212
204
  end # describe "works with CONSTANTS" do
@@ -221,16 +213,16 @@ describe DebugMe do
221
213
  it "supports a single class CONSTANT" do
222
214
  out_string = debug_me(file:nil,header:false){'WorldView::A'}
223
215
  assert out_string.include? "WorldView::A -=> #{WorldView::A}"
224
- out_string.split("\n").size.must_equal 1
216
+ _(out_string.split("\n").size).must_equal 1
225
217
  end
226
218
 
227
- it "supports multible class CONSTANTS" do
219
+ it "supports multiple class CONSTANTS" do
228
220
  out_string = debug_me(file:nil,header:false){[
229
221
  'WorldView::A', 'WorldView::B', 'WorldView::C']}
230
222
  assert out_string.include? "WorldView::A -=> #{WorldView::A}"
231
223
  assert out_string.include? "WorldView::B -=> #{WorldView::B}"
232
224
  assert out_string.include? "WorldView::C -=> #{WorldView::C}"
233
- out_string.split("\n").size.must_equal 3
225
+ _(out_string.split("\n").size).must_equal 3
234
226
  end
235
227
 
236
228
  it "shows all class CONSTANTS" do
@@ -241,10 +233,10 @@ describe DebugMe do
241
233
  assert out_string.include? "C -=> #{WorldView::C}"
242
234
  assert out_string.include? 'MY_CONSTANT -=> "Jesus"'
243
235
 
244
- out_string.include?("out_string -=> ").must_equal false
245
- out_string.include?("@d -=> ").must_equal false
236
+ _(out_string.include?("out_string -=> ")).must_equal false
237
+ _(out_string.include?("@d -=> ")).must_equal false
246
238
 
247
- out_string.split("\n").size.must_equal WorldView.constants.size
239
+ _(out_string.split("\n").size).must_equal WorldView.constants.size
248
240
  end
249
241
 
250
242
  end # describe "works with class CONSTANTS" do
@@ -252,12 +244,12 @@ describe DebugMe do
252
244
  describe "works with a Logger class" do
253
245
 
254
246
  it 'default logger class is nil' do
255
- DebugMeDefaultOptions[:logger].must_equal nil
247
+ _(DebugMeDefaultOptions[:logger]).must_be_nil
256
248
  end
257
249
 
258
250
  it 'works with standard ruby Logger class' do
259
251
  logger_output_path = Pathname.pwd + 'logger_class_output.txt'
260
- logger_output_path.exist?.must_equal false
252
+ _(logger_output_path.exist?).must_equal false
261
253
 
262
254
  logger = Logger.new(logger_output_path)
263
255
  logger.level = Logger::DEBUG
@@ -276,18 +268,140 @@ describe DebugMe do
276
268
 
277
269
  lines = logger_output_path.read.split("\n")
278
270
 
279
- lines.size.must_equal 2
271
+ _(lines.size).must_equal 2
280
272
 
281
- lines[0].start_with?('# Logfile created on').must_equal true
282
- lines[1].start_with?('D, [').must_equal true
283
- lines[1].include?('DEBUG').must_equal true
284
- lines[1].include?('Hello World').must_equal true
285
- lines[1].include?('debug_me_test.rb').must_equal true
286
- lines[1].include?(out_string.chomp).must_equal true
273
+ _(lines[0].start_with?('# Logfile created on')).must_equal true
274
+ _(lines[1].start_with?('D, [')).must_equal true
275
+ _(lines[1].include?('DEBUG')).must_equal true
276
+ _(lines[1].include?('Hello World')).must_equal true
277
+ _(lines[1].include?('debug_me_test.rb')).must_equal true
278
+ _(lines[1].include?(out_string.chomp)).must_equal true
287
279
 
288
280
  logger_output_path.delete
289
281
  end
290
282
 
291
283
  end
292
284
 
285
+ describe "$DEBUG_ME global flag" do
286
+
287
+ before do
288
+ # Save the original state
289
+ @original_debug_me = $DEBUG_ME
290
+ end
291
+
292
+ after do
293
+ # Restore the original state after each test
294
+ $DEBUG_ME = @original_debug_me
295
+ end
296
+
297
+ it 'is true by default' do
298
+ _($DEBUG_ME).must_equal true
299
+ end
300
+
301
+ it 'returns nil when $DEBUG_ME is false' do
302
+ $DEBUG_ME = false
303
+ a = 42
304
+ result = debug_me(file: nil, header: false) { :a }
305
+ _(result).must_be_nil
306
+ end
307
+
308
+ it 'produces no output when $DEBUG_ME is false' do
309
+ $DEBUG_ME = false
310
+ a = 42
311
+ result = debug_me(file: nil) { :a }
312
+ _(result).must_be_nil
313
+ end
314
+
315
+ it 'works normally when $DEBUG_ME is true' do
316
+ $DEBUG_ME = true
317
+ a = 42
318
+ result = debug_me(file: nil, header: false) { :a }
319
+ _(result).wont_be_nil
320
+ assert result.include?("a -=> 42")
321
+ end
322
+
323
+ it 'can be toggled on and off' do
324
+ # Start with it on
325
+ $DEBUG_ME = true
326
+ a = 42
327
+ result1 = debug_me(file: nil, header: false) { :a }
328
+ _(result1).wont_be_nil
329
+ assert result1.include?("a -=> 42")
330
+
331
+ # Turn it off
332
+ $DEBUG_ME = false
333
+ result2 = debug_me(file: nil, header: false) { :a }
334
+ _(result2).must_be_nil
335
+
336
+ # Turn it back on
337
+ $DEBUG_ME = true
338
+ result3 = debug_me(file: nil, header: false) { :a }
339
+ _(result3).wont_be_nil
340
+ assert result3.include?("a -=> 42")
341
+ end
342
+
343
+ it 'does not evaluate the block when disabled' do
344
+ $DEBUG_ME = false
345
+ side_effect = false
346
+
347
+ result = debug_me(file: nil) do
348
+ side_effect = true # This should not execute
349
+ :dummy
350
+ end
351
+
352
+ _(result).must_be_nil
353
+ _(side_effect).must_equal false
354
+ end
355
+
356
+ it 'works with all debug_me features when enabled' do
357
+ $DEBUG_ME = true
358
+ @instance_var = 'test'
359
+ local_var = 'local'
360
+
361
+ result = debug_me(file: nil, header: false) { [:@instance_var, :local_var] }
362
+
363
+ _(result).wont_be_nil
364
+ assert result.include?('@instance_var')
365
+ assert result.include?('local_var')
366
+ end
367
+
368
+ end # describe "$DEBUG_ME global flag" do
369
+
370
+ describe "ENV['DEBUG_ME'] environment variable" do
371
+
372
+ it 'initializes $DEBUG_ME from environment variable if set' do
373
+ # This test documents that $DEBUG_ME can be controlled via ENV['DEBUG_ME']
374
+ # The actual initialization happens when lib/debug_me.rb is loaded
375
+ # Users can set DEBUG_ME=false before requiring the gem to disable it
376
+
377
+ # Verify current state is set (either from ENV or default true)
378
+ _($DEBUG_ME).wont_be_nil
379
+
380
+ # Document that users can override at runtime
381
+ original = $DEBUG_ME
382
+ $DEBUG_ME = false
383
+ _($DEBUG_ME).must_equal false
384
+ $DEBUG_ME = original
385
+ end
386
+
387
+ it 'can be controlled by setting $DEBUG_ME directly at runtime' do
388
+ # Save original
389
+ original = $DEBUG_ME
390
+
391
+ # Test setting various values
392
+ $DEBUG_ME = false
393
+ _($DEBUG_ME).must_equal false
394
+
395
+ $DEBUG_ME = true
396
+ _($DEBUG_ME).must_equal true
397
+
398
+ $DEBUG_ME = nil
399
+ _($DEBUG_ME).must_be_nil
400
+
401
+ # Restore
402
+ $DEBUG_ME = original
403
+ end
404
+
405
+ end # describe "ENV['DEBUG_ME'] environment variable" do
406
+
293
407
  end # describe DebugMe do
data/tests/env_test.rb ADDED
@@ -0,0 +1,71 @@
1
+ #!/usr/bin/env ruby
2
+ # Test script to verify ENV['DEBUG_ME'] initialization behavior
3
+ # This must be run as a separate process to test initialization
4
+
5
+ require 'minitest/autorun'
6
+
7
+ describe "DEBUG_ME environment variable initialization" do
8
+
9
+ it "defaults to true when ENV['DEBUG_ME'] is not set" do
10
+ # Remove the env var if it exists
11
+ env_value = ENV.delete('DEBUG_ME')
12
+
13
+ # Load the library fresh (in a subprocess to get clean initialization)
14
+ result = `ruby -I./lib -e 'require "debug_me"; p $DEBUG_ME' 2>&1`
15
+ _(result.strip).must_equal "true"
16
+
17
+ # Restore if it was set
18
+ ENV['DEBUG_ME'] = env_value if env_value
19
+ end
20
+
21
+ it "sets to false when ENV['DEBUG_ME'] is 'false'" do
22
+ result = `DEBUG_ME=false ruby -I./lib -e 'require "debug_me"; p $DEBUG_ME' 2>&1`
23
+ _(result.strip).must_equal "false"
24
+ end
25
+
26
+ it "sets to false when ENV['DEBUG_ME'] is 'no'" do
27
+ result = `DEBUG_ME=no ruby -I./lib -e 'require "debug_me"; p $DEBUG_ME' 2>&1`
28
+ _(result.strip).must_equal "false"
29
+ end
30
+
31
+ it "sets to false when ENV['DEBUG_ME'] is '0'" do
32
+ result = `DEBUG_ME=0 ruby -I./lib -e 'require "debug_me"; p $DEBUG_ME' 2>&1`
33
+ _(result.strip).must_equal "false"
34
+ end
35
+
36
+ it "sets to false when ENV['DEBUG_ME'] is 'off'" do
37
+ result = `DEBUG_ME=off ruby -I./lib -e 'require "debug_me"; p $DEBUG_ME' 2>&1`
38
+ _(result.strip).must_equal "false"
39
+ end
40
+
41
+ it "sets to false when ENV['DEBUG_ME'] is empty string" do
42
+ result = `DEBUG_ME= ruby -I./lib -e 'require "debug_me"; p $DEBUG_ME' 2>&1`
43
+ _(result.strip).must_equal "false"
44
+ end
45
+
46
+ it "sets to true when ENV['DEBUG_ME'] is 'true'" do
47
+ result = `DEBUG_ME=true ruby -I./lib -e 'require "debug_me"; p $DEBUG_ME' 2>&1`
48
+ _(result.strip).must_equal "true"
49
+ end
50
+
51
+ it "sets to true when ENV['DEBUG_ME'] is 'yes'" do
52
+ result = `DEBUG_ME=yes ruby -I./lib -e 'require "debug_me"; p $DEBUG_ME' 2>&1`
53
+ _(result.strip).must_equal "true"
54
+ end
55
+
56
+ it "sets to true when ENV['DEBUG_ME'] is '1'" do
57
+ result = `DEBUG_ME=1 ruby -I./lib -e 'require "debug_me"; p $DEBUG_ME' 2>&1`
58
+ _(result.strip).must_equal "true"
59
+ end
60
+
61
+ it "sets to true when ENV['DEBUG_ME'] is 'on'" do
62
+ result = `DEBUG_ME=on ruby -I./lib -e 'require "debug_me"; p $DEBUG_ME' 2>&1`
63
+ _(result.strip).must_equal "true"
64
+ end
65
+
66
+ it "sets to true when ENV['DEBUG_ME'] is any other value" do
67
+ result = `DEBUG_ME=whatever ruby -I./lib -e 'require "debug_me"; p $DEBUG_ME' 2>&1`
68
+ _(result.strip).must_equal "true"
69
+ end
70
+
71
+ end
data/tests/world_view.rb CHANGED
@@ -40,4 +40,23 @@ class WorldView
40
40
  def six
41
41
  debug_me(tag:'How did I get here?', levels: 5)
42
42
  end
43
+
44
+ def test_single_class_var
45
+ debug_me(file:nil, header:false){:@@d}
46
+ end
47
+
48
+ def test_multiple_class_vars
49
+ debug_me(file:nil, header:false){[:@@d, :@@e, :@@f]}
50
+ end
51
+
52
+ def test_all_class_vars
53
+ debug_me(
54
+ file:nil,
55
+ header:false,
56
+ lvar: false,
57
+ ivar: false,
58
+ cvar: true,
59
+ cconst: false
60
+ ){}
61
+ end
43
62
  end # class WorldView
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: debug_me
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dewayne VanHoozer
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2023-11-02 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: bundler
@@ -38,6 +37,34 @@ dependencies:
38
37
  - - ">="
39
38
  - !ruby/object:Gem::Version
40
39
  version: '0'
40
+ - !ruby/object:Gem::Dependency
41
+ name: amazing_print
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ type: :development
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ - !ruby/object:Gem::Dependency
55
+ name: minitest
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '5.0'
61
+ type: :development
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '5.0'
41
68
  description: |-
42
69
  This thing is pretty old. There are much better
43
70
  ways of debugging in a complex application. But,
@@ -52,21 +79,27 @@ files:
52
79
  - ".envrc"
53
80
  - ".gitignore"
54
81
  - ".rultor.yml"
82
+ - CHANGELOG.md
55
83
  - Gemfile
56
84
  - LICENSE.txt
57
85
  - README.md
58
86
  - Rakefile
59
87
  - debug_me.gemspec
88
+ - debug_me.jpg
60
89
  - lib/debug_me.rb
61
90
  - lib/debug_me/version.rb
62
91
  - rubygems.yml.asc
63
92
  - tests/debug_me_test.rb
93
+ - tests/env_test.rb
64
94
  - tests/world_view.rb
65
95
  homepage: http://github.com/MadBomber/debug_me
66
96
  licenses:
67
- - You want it, its yours
68
- metadata: {}
69
- post_install_message:
97
+ - MIT
98
+ metadata:
99
+ homepage_uri: https://github.com/MadBomber/debug_me
100
+ source_code_uri: https://github.com/MadBomber/debug_me
101
+ bug_tracker_uri: https://github.com/MadBomber/debug_me/issues
102
+ changelog_uri: https://github.com/MadBomber/debug_me/blob/master/CHANGELOG.md
70
103
  rdoc_options: []
71
104
  require_paths:
72
105
  - lib
@@ -74,15 +107,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
74
107
  requirements:
75
108
  - - ">="
76
109
  - !ruby/object:Gem::Version
77
- version: '0'
110
+ version: 2.3.0
78
111
  required_rubygems_version: !ruby/object:Gem::Requirement
79
112
  requirements:
80
113
  - - ">="
81
114
  - !ruby/object:Gem::Version
82
115
  version: '0'
83
116
  requirements: []
84
- rubygems_version: 3.4.21
85
- signing_key:
117
+ rubygems_version: 3.7.2
86
118
  specification_version: 4
87
119
  summary: A tool to print the labeled value of variables.
88
120
  test_files: []