puts_debuggerer 0.13.5 → 1.0.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/CHANGELOG.md +9 -0
- data/LICENSE.txt +1 -1
- data/README.md +157 -85
- data/VERSION +1 -1
- data/lib/pd.rb +2 -0
- data/lib/puts_debuggerer/core_ext/kernel.rb +8 -0
- data/lib/puts_debuggerer.rb +5 -4
- metadata +6 -47
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d233d55e6a6fd44243d0c03cc1a0d94452e8d6ca5ad1c363b286094ecbbea19b
|
4
|
+
data.tar.gz: cdc0375b20f5289213ebe2177d6812423654ed09e2405e490b60bb244011e923
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd63f2cfba6602e0e090e565949782fe734ab62ca4f233114cdc7abb1b08ca213f8810f186f7ee8c5c63c9edfe04c39bc5661fc18ecd5ff20be18cd4fe3ef63c
|
7
|
+
data.tar.gz: 7c485c0dece0ee52bf9913b96620746974d8f28191a7ff182faeea18c84b65b331ba87d98b4038d60193c50170c5707d2eeaa0788bdc43950474dc6c28f5c0b8
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## 1.0.1
|
4
|
+
|
5
|
+
- Fix issue with deleting `pd` options from a `Hash` if it was the only argument breaking the guarantee that `pd` never modifies the printed object, which could cause bugs.
|
6
|
+
- Fix issue with attempting to modify a frozen `Hash` when passing a frozen `Hash` as the only argument for `pd` method
|
7
|
+
|
8
|
+
## 1.0.0
|
9
|
+
|
10
|
+
- Support including class/method after file/line in every `pd` printout
|
11
|
+
|
3
12
|
## 0.13.5
|
4
13
|
|
5
14
|
- Fix not printing source line in Rails app w/ Pry
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,17 +1,19 @@
|
|
1
|
-
# Puts Debuggerer
|
2
|
-
##
|
1
|
+
# Puts Debuggerer 1.0.1
|
2
|
+
## Debugger-less Debugging FTW
|
3
|
+
## [Featured in State of the Art Rails 2023 Edition](https://github.com/DanielVartanov/state-of-the-art-rails/tree/bd7a509f5f0ab07cebfeada779b5c73e1eaf22ed)
|
3
4
|
[](http://badge.fury.io/rb/puts_debuggerer)
|
4
|
-
[](https://travis-ci.org/AndyObtiva/puts_debuggerer)
|
5
5
|
[](https://coveralls.io/github/AndyObtiva/puts_debuggerer?branch=master)
|
6
6
|
[](https://codeclimate.com/github/AndyObtiva/puts_debuggerer/maintainability)
|
7
7
|
|
8
8
|
(credit to Aaron Patterson for partial inspiration: https://tenderlovemaking.com/2016/02/05/i-am-a-puts-debuggerer.html)
|
9
9
|
|
10
|
+
If you like [Awesome_Print](https://rubygems.org/gems/awesome_print) (or [Amazing_Print](https://github.com/amazing-print/amazing_print)), you will love Puts Debuggerer (which builds upon them)!
|
11
|
+
|
10
12
|
Debuggers are great! They help us troubleshoot complicated programming problems by inspecting values produced by code, line by line. They are invaluable when trying to understand what is going on in a large application composed of thousands or millions of lines of code.
|
11
13
|
|
12
|
-
In day-to-day test-driven development and simple app debugging though, a puts statement can be a lot quicker in revealing what is going on than halting execution completely just to inspect a single value or a few. This is certainly true when writing the simplest possible code that could possibly work, and running a test every few seconds or minutes. Still, there are a number of problems with puts debugging, like difficulty in locating puts statements in a large output log, knowing which
|
14
|
+
In day-to-day test-driven development and simple app debugging though, a puts statement can be a lot quicker in revealing what is going on than halting execution completely just to inspect a single value or a few. This is certainly true when writing the simplest possible code that could possibly work, and running a test every few seconds or minutes. Still, there are a number of problems with puts debugging, like difficulty in locating puts statements in a large output log, knowing which files, line numbers, and methods the puts statements were invoked from, identifying which variables were printed, and seeing the content of structured hashes and arrays in an understandable format.
|
13
15
|
|
14
|
-
Enter [puts_debuggerer](https://rubygems.org/gems/puts_debuggerer)! A guilt-free puts debugging Ruby gem FTW that prints file names, line numbers, code statements, headers, footers, stack traces
|
16
|
+
Enter [puts_debuggerer](https://rubygems.org/gems/puts_debuggerer)! A guilt-free puts debugging Ruby gem FTW that prints file names, line numbers, class names, method names, code statements, headers, footers, and stack traces; and formats output nicely courtesy of [awesome_print](https://rubygems.org/gems/awesome_print) (or [amazing_print](https://github.com/amazing-print/amazing_print) if you prefer).
|
15
17
|
|
16
18
|
[puts_debuggerer](https://rubygems.org/gems/puts_debuggerer) automates tips mentioned in [this blog post](https://tenderlovemaking.com/2016/02/05/i-am-a-puts-debuggerer.html) by Aaron Patterson using the `pd` method available everywhere after requiring the [gem](https://rubygems.org/gems/puts_debuggerer).
|
17
19
|
|
@@ -20,18 +22,25 @@ Basic Example:
|
|
20
22
|
```ruby
|
21
23
|
# /Users/User/trivia_app.rb # line 1
|
22
24
|
require 'pd' # line 2
|
23
|
-
|
24
|
-
|
25
|
+
class TriviaApp # line 3
|
26
|
+
def question # line 4
|
27
|
+
bug_or_band = 'Beatles' # line 5
|
28
|
+
pd bug_or_band # line 6
|
29
|
+
end # line 7
|
30
|
+
end # line 8
|
31
|
+
TriviaApp.new.question # line 9
|
25
32
|
```
|
26
33
|
|
27
34
|
Output:
|
28
35
|
|
29
36
|
```bash
|
30
|
-
[PD] /Users/User/trivia_app.rb:
|
31
|
-
> pd bug_or_band
|
32
|
-
=> "
|
37
|
+
[PD] /Users/User/trivia_app.rb:6 in TriviaApp.question
|
38
|
+
> pd bug_or_band # line 6
|
39
|
+
=> "Beatles"
|
33
40
|
```
|
34
41
|
|
42
|
+
`pd` revealed that the variable contains the band name "Beatles" not the bug "Beetle", in addition to revealing the printed code statement `pd bug_or_band`, the file name `/Users/User/trivia_app.rb`, the line number `6`, the class name `TriviaApp`, and the method name `question`.
|
43
|
+
|
35
44
|
## Background
|
36
45
|
|
37
46
|
It can be quite frustrating to lose puts statements in a large output or log file. One way to help find them is add an announcer (e.g. `puts "The Order Total"`) or a header (e.g. `puts '>'*80`) before every puts statement. Unfortunately, that leads to repetitive wasteful effort that adds up quickly over many work sessions and interrupts thinking flow while solving problems.
|
@@ -63,7 +72,7 @@ Which gets lost in a logging stream such as:
|
|
63
72
|
(0.2ms) COMMIT
|
64
73
|
```
|
65
74
|
|
66
|
-
Here is a simple example using `pd` instead, which provides everything the puts statements above provide in addition to deducing the file name
|
75
|
+
Here is a simple example using `pd` instead, which provides everything the puts statements above provide in addition to deducing the file name, line number, class name, and method name automatically for dead-easy debugging:
|
67
76
|
|
68
77
|
```ruby
|
69
78
|
pd order_total
|
@@ -77,7 +86,7 @@ Output:
|
|
77
86
|
(0.2ms) BEGIN
|
78
87
|
SQL (0.3ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "environment"], ["value", "development"], ["created_at", 2017-08-24 22:56:52 UTC], ["updated_at", 2017-08-24 22:56:52 UTC]]
|
79
88
|
(0.3ms) COMMIT
|
80
|
-
[PD] /Users/User/ordering/order.rb:39
|
89
|
+
[PD] /Users/User/ordering/order.rb:39 in Order.calculate_order_total
|
81
90
|
> pd order_total
|
82
91
|
=> 195.50
|
83
92
|
ActiveRecord::InternalMetadata Load (0.3ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", :environment], ["LIMIT", 1]]
|
@@ -98,19 +107,19 @@ Output:
|
|
98
107
|
```
|
99
108
|
(2.7ms) CREATE TABLE "ar_internal_metadata" ("key" character varying PRIMARY KEY, "value" character varying, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
|
100
109
|
ActiveRecord::InternalMetadata Load (0.4ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", :environment], ["LIMIT", 1]]
|
101
|
-
[PD] /Users/User/ordering/order.rb:39
|
110
|
+
[PD] /Users/User/ordering/order.rb:39 in Order.calculate_order_total
|
102
111
|
> pd order_total
|
103
112
|
=> 195.50
|
104
113
|
(0.2ms) BEGIN
|
105
114
|
SQL (0.3ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "environment"], ["value", "development"], ["created_at", 2017-08-24 22:56:52 UTC], ["updated_at", 2017-08-24 22:56:52 UTC]]
|
106
115
|
(0.3ms) COMMIT
|
107
|
-
[PD] /Users/User/ordering/order.rb:40
|
116
|
+
[PD] /Users/User/ordering/order.rb:40 in Order.calculate_order_total
|
108
117
|
> pd order_summary
|
109
118
|
=> "Pragmatic Ruby Book"
|
110
119
|
ActiveRecord::InternalMetadata Load (0.3ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", :environment], ["LIMIT", 1]]
|
111
120
|
(0.2ms) BEGIN
|
112
121
|
(0.2ms) COMMIT
|
113
|
-
[PD] /Users/User/ordering/order.rb:41
|
122
|
+
[PD] /Users/User/ordering/order.rb:41 in Order.calculate_order_total
|
114
123
|
> pd order_details
|
115
124
|
=> "[Hard Cover] Pragmatic Ruby Book - English Version"
|
116
125
|
```
|
@@ -137,19 +146,19 @@ Output:
|
|
137
146
|
(2.7ms) CREATE TABLE "ar_internal_metadata" ("key" character varying PRIMARY KEY, "value" character varying, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
|
138
147
|
ActiveRecord::InternalMetadata Load (0.4ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", :environment], ["LIMIT", 1]]
|
139
148
|
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
140
|
-
[PD] /Users/User/ordering/order.rb:39
|
149
|
+
[PD] /Users/User/ordering/order.rb:39 in Order.calculate_order_total
|
141
150
|
> pd order_total, header: true
|
142
151
|
=> 195.50
|
143
152
|
(0.2ms) BEGIN
|
144
153
|
SQL (0.3ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "environment"], ["value", "development"], ["created_at", 2017-08-24 22:56:52 UTC], ["updated_at", 2017-08-24 22:56:52 UTC]]
|
145
154
|
(0.3ms) COMMIT
|
146
|
-
[PD] /Users/User/ordering/order.rb:40
|
155
|
+
[PD] /Users/User/ordering/order.rb:40 in Order.calculate_order_total
|
147
156
|
> pd order_summary
|
148
157
|
=> "Pragmatic Ruby Book"
|
149
158
|
ActiveRecord::InternalMetadata Load (0.3ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", :environment], ["LIMIT", 1]]
|
150
159
|
(0.2ms) BEGIN
|
151
160
|
(0.2ms) COMMIT
|
152
|
-
[PD] /Users/User/ordering/order.rb:41
|
161
|
+
[PD] /Users/User/ordering/order.rb:41 in Order.calculate_order_total
|
153
162
|
> pd order_details
|
154
163
|
=> "[Hard Cover] Pragmatic Ruby Book - English Version"
|
155
164
|
```
|
@@ -176,19 +185,19 @@ Output:
|
|
176
185
|
(2.7ms) CREATE TABLE "ar_internal_metadata" ("key" character varying PRIMARY KEY, "value" character varying, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
|
177
186
|
ActiveRecord::InternalMetadata Load (0.4ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", :environment], ["LIMIT", 1]]
|
178
187
|
################################################################################
|
179
|
-
[PD] /Users/User/ordering/order.rb:39
|
188
|
+
[PD] /Users/User/ordering/order.rb:39 in Order.calculate_order_total
|
180
189
|
> pd order_total, header: '>'*80
|
181
190
|
=> 195.50
|
182
191
|
(0.2ms) BEGIN
|
183
192
|
SQL (0.3ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "environment"], ["value", "development"], ["created_at", 2017-08-24 22:56:52 UTC], ["updated_at", 2017-08-24 22:56:52 UTC]]
|
184
193
|
(0.3ms) COMMIT
|
185
|
-
[PD] /Users/User/ordering/order.rb:40
|
194
|
+
[PD] /Users/User/ordering/order.rb:40 in Order.calculate_order_total
|
186
195
|
> pd order_summary
|
187
196
|
=> "Pragmatic Ruby Book"
|
188
197
|
ActiveRecord::InternalMetadata Load (0.3ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", :environment], ["LIMIT", 1]]
|
189
198
|
(0.2ms) BEGIN
|
190
199
|
(0.2ms) COMMIT
|
191
|
-
[PD] /Users/User/ordering/order.rb:41
|
200
|
+
[PD] /Users/User/ordering/order.rb:41 in Order.calculate_order_total
|
192
201
|
> pd order_details, footer: '<'*80
|
193
202
|
=> "[Hard Cover] Pragmatic Ruby Book - English Version"
|
194
203
|
################################################################################
|
@@ -216,7 +225,7 @@ Output:
|
|
216
225
|
(2.7ms) CREATE TABLE "ar_internal_metadata" ("key" character varying PRIMARY KEY, "value" character varying, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
|
217
226
|
ActiveRecord::InternalMetadata Load (0.4ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", :environment], ["LIMIT", 1]]
|
218
227
|
********************************************************************************
|
219
|
-
[PD] /Users/User/ordering/order.rb:39
|
228
|
+
[PD] /Users/User/ordering/order.rb:39 in Order.calculate_order_total
|
220
229
|
> pd order_total, caller: true, wrapper: true
|
221
230
|
=> 195.50
|
222
231
|
/Users/User/.rvm/gems/ruby-2.7.1/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
|
@@ -260,13 +269,13 @@ Output:
|
|
260
269
|
(0.2ms) BEGIN
|
261
270
|
SQL (0.3ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "environment"], ["value", "development"], ["created_at", 2017-08-24 22:56:52 UTC], ["updated_at", 2017-08-24 22:56:52 UTC]]
|
262
271
|
(0.3ms) COMMIT
|
263
|
-
[PD] /Users/User/ordering/order.rb:40
|
272
|
+
[PD] /Users/User/ordering/order.rb:40 in Order.calculate_order_total
|
264
273
|
> pd order_summary
|
265
274
|
=> "Pragmatic Ruby Book"
|
266
275
|
ActiveRecord::InternalMetadata Load (0.3ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", :environment], ["LIMIT", 1]]
|
267
276
|
(0.2ms) BEGIN
|
268
277
|
(0.2ms) COMMIT
|
269
|
-
[PD] /Users/User/ordering/order.rb:41
|
278
|
+
[PD] /Users/User/ordering/order.rb:41 in Order.calculate_order_total
|
270
279
|
> pd order_details
|
271
280
|
=> "[Hard Cover] Pragmatic Ruby Book - English Version"
|
272
281
|
```
|
@@ -291,7 +300,7 @@ pd order_details
|
|
291
300
|
(2.7ms) CREATE TABLE "ar_internal_metadata" ("key" character varying PRIMARY KEY, "value" character varying, "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL)
|
292
301
|
ActiveRecord::InternalMetadata Load (0.4ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", :environment], ["LIMIT", 1]]
|
293
302
|
********************************************************************************
|
294
|
-
[PD] /Users/User/ordering/order.rb:39
|
303
|
+
[PD] /Users/User/ordering/order.rb:39 in Order.calculate_order_total
|
295
304
|
> pd order_total, caller: 3, wrapper: true
|
296
305
|
=> 195.50
|
297
306
|
/Users/User/.rvm/gems/ruby-2.7.1/gems/bootsnap-1.4.6/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require'
|
@@ -301,13 +310,13 @@ pd order_details
|
|
301
310
|
(0.2ms) BEGIN
|
302
311
|
SQL (0.3ms) INSERT INTO "ar_internal_metadata" ("key", "value", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "key" [["key", "environment"], ["value", "development"], ["created_at", 2017-08-24 22:56:52 UTC], ["updated_at", 2017-08-24 22:56:52 UTC]]
|
303
312
|
(0.3ms) COMMIT
|
304
|
-
[PD] /Users/User/ordering/order.rb:40
|
313
|
+
[PD] /Users/User/ordering/order.rb:40 in Order.calculate_order_total
|
305
314
|
> pd order_summary
|
306
315
|
=> "Pragmatic Ruby Book"
|
307
316
|
ActiveRecord::InternalMetadata Load (0.3ms) SELECT "ar_internal_metadata".* FROM "ar_internal_metadata" WHERE "ar_internal_metadata"."key" = $1 LIMIT $2 [["key", :environment], ["LIMIT", 1]]
|
308
317
|
(0.2ms) BEGIN
|
309
318
|
(0.2ms) COMMIT
|
310
|
-
[PD] /Users/User/ordering/order.rb:41
|
319
|
+
[PD] /Users/User/ordering/order.rb:41 in Order.calculate_order_total
|
311
320
|
> pd order_details
|
312
321
|
=> "[Hard Cover] Pragmatic Ruby Book - English Version"
|
313
322
|
```
|
@@ -320,10 +329,10 @@ There are many more options and features in [puts_debuggerer](https://rubygems.o
|
|
320
329
|
|
321
330
|
This is the recommended way for installing in [Rails](rubyonrails.org) apps in addition to configuring the [`app_path` option](#putsdebuggererapp_path).
|
322
331
|
|
323
|
-
Add the following to bundler's `Gemfile
|
332
|
+
Add the following to bundler's `Gemfile` (in Rails, you can optionally limit to the `:development` and `:test` groups).
|
324
333
|
|
325
334
|
```ruby
|
326
|
-
gem 'puts_debuggerer', '~> 0.
|
335
|
+
gem 'puts_debuggerer', '~> 1.0.1'
|
327
336
|
```
|
328
337
|
|
329
338
|
Run:
|
@@ -334,12 +343,31 @@ bundle
|
|
334
343
|
|
335
344
|
Optionally, you may configure the [Rails](rubyonrails.org) initializer `config/initializers/puts_debuggerer_options.rb` with further customizations as per the [Options](#options) section below.
|
336
345
|
|
346
|
+
Also, you may want to add the following to the initializer too if you limited the `puts_debuggerer` gem to the `:development` and `:test` groups:
|
347
|
+
|
348
|
+
```ruby
|
349
|
+
unless Rails.env.development? || Rails.env.test?
|
350
|
+
def pd(*args, &block) # `pd(...)` in Ruby 2.7+
|
351
|
+
# No Op (just a stub in case developers forget troubleshooting pd calls in the code and deploy to production)
|
352
|
+
end
|
353
|
+
end
|
354
|
+
```
|
355
|
+
|
356
|
+
The Rails `config.log_level` is assumed to be `:debug`. If you have it set to something else like `:info`, then you need to update `PutsDebuggerer.printer` to print at a different log level (e.g. `:info`) by adding the following code to the initializer above (this code is a modification of the default at `PutsDebuggerer::PRINTER_RAILS`):
|
357
|
+
|
358
|
+
```ruby
|
359
|
+
PutsDebuggerer.printer = lambda do |output|
|
360
|
+
puts output if Rails.env.test?
|
361
|
+
Rails.logger.info(output)
|
362
|
+
end
|
363
|
+
```
|
364
|
+
|
337
365
|
### Option 2: Manual
|
338
366
|
|
339
367
|
Or manually install and require library.
|
340
368
|
|
341
369
|
```bash
|
342
|
-
gem install puts_debuggerer -
|
370
|
+
gem install puts_debuggerer -v1.0.1
|
343
371
|
```
|
344
372
|
|
345
373
|
```ruby
|
@@ -364,7 +392,7 @@ Still, if you do not need it, you may disable by setting `PutsDebuggerer.print_e
|
|
364
392
|
PutsDebuggerer.print_engine = :puts
|
365
393
|
```
|
366
394
|
|
367
|
-
If you also avoid requiring 'awesome_print', PutsDebuggerer
|
395
|
+
If you also avoid requiring 'awesome_print', PutsDebuggerer will NOT require it either if it sees that you have a different `print_engine`. In fact, you may switch to another print engine if you prefer like [amazing_print](https://github.com/amazing-print/amazing_print) as [explained here](https://github.com/AndyObtiva/puts_debuggerer#putsdebuggererprint_engine).
|
368
396
|
|
369
397
|
You may also avoid requiring in Bundler `Gemfile` with `require: false`:
|
370
398
|
|
@@ -375,13 +403,39 @@ gem "puts_debuggerer"
|
|
375
403
|
|
376
404
|
### Usage
|
377
405
|
|
378
|
-
First, add `pd` method anywhere in your code to display details about an object or expression (if you're used to awesome_print, you're in luck! puts_debuggerer includes awesome_print as the default print engine for output).
|
406
|
+
First, add `pd` method anywhere in your code to display details about an object or expression (if you're used to awesome_print, you're in luck! puts_debuggerer includes awesome_print (or amazing_print if preferred) as the default print engine for output).
|
407
|
+
|
408
|
+
Example:
|
409
|
+
|
410
|
+
```ruby
|
411
|
+
# /Users/User/trivia_app.rb # line 1
|
412
|
+
require 'pd' # line 2
|
413
|
+
class TriviaApp # line 3
|
414
|
+
def question # line 4
|
415
|
+
bug_or_band = 'Beatles' # line 5
|
416
|
+
pd bug_or_band # line 6
|
417
|
+
end # line 7
|
418
|
+
end # line 8
|
419
|
+
TriviaApp.new.question # line 9
|
420
|
+
```
|
421
|
+
|
422
|
+
Output:
|
423
|
+
|
424
|
+
```bash
|
425
|
+
[PD] /Users/User/trivia_app.rb:6 in TriviaApp.question
|
426
|
+
> pd bug_or_band # line 6
|
427
|
+
=> "Beatles"
|
428
|
+
```
|
429
|
+
|
430
|
+
In addition to the object/expression output, you get to see the source file name, line number, class name, method name, and source code to help you debug and troubleshoot problems quicker (it even works in IRB).
|
431
|
+
|
432
|
+
You can use `pd` at the top-level main object too, and it prings `Object.<main>` for the class/method.
|
379
433
|
|
380
434
|
Example:
|
381
435
|
|
382
436
|
```ruby
|
383
437
|
# /Users/User/finance_calculator_app/pd_test.rb # line 1
|
384
|
-
bug = '
|
438
|
+
bug = 'Beetle' # line 2
|
385
439
|
pd "Show me the source of the bug: #{bug}" # line 3
|
386
440
|
pd "Show me the result of the calculation: #{(12.0/3.0)}" # line 4
|
387
441
|
```
|
@@ -389,19 +443,18 @@ pd "Show me the result of the calculation: #{(12.0/3.0)}" # line 4
|
|
389
443
|
Output:
|
390
444
|
|
391
445
|
```bash
|
392
|
-
[PD] /Users/User/finance_calculator_app/pd_test.rb:3
|
446
|
+
[PD] /Users/User/finance_calculator_app/pd_test.rb:3 in Object.<main>
|
393
447
|
> pd "Show me the source of the bug: #{bug}"
|
394
|
-
=> "Show me the source of the bug:
|
395
|
-
[PD] /Users/User/finance_calculator_app/pd_test.rb:4
|
448
|
+
=> "Show me the source of the bug: Beetle"
|
449
|
+
[PD] /Users/User/finance_calculator_app/pd_test.rb:4 in Object.<main>
|
396
450
|
> pd "Show me the result of the calculation: #{(12.0/3.0)}"
|
397
451
|
=> "Show me the result of the calculation: 4.0"
|
398
452
|
```
|
399
453
|
|
400
|
-
In addition to the main object/expression output, you get to see the source file name, line number, and source code to help you debug and troubleshoot problems quicker (it even works in IRB).
|
401
|
-
|
402
454
|
Second, quickly locate printed lines using the Find feature (e.g. CTRL+F) by looking for:
|
403
455
|
* [PD]
|
404
456
|
* file:line_number
|
457
|
+
* class.method
|
405
458
|
* known ruby expression.
|
406
459
|
|
407
460
|
Third, easily remove your ` pd ` statements via the source code Find feature once done debugging.
|
@@ -419,7 +472,7 @@ greeting = "Hello #{pd(name)}" # line 3
|
|
419
472
|
Output:
|
420
473
|
|
421
474
|
```bash
|
422
|
-
[PD] /Users/User/greeting_app/pd_test.rb:3
|
475
|
+
[PD] /Users/User/greeting_app/pd_test.rb:3 in Object.<main>
|
423
476
|
> greeting = "Hello #{pd(name)}"
|
424
477
|
=> "Hello Robert"
|
425
478
|
```
|
@@ -463,7 +516,7 @@ Prints out:
|
|
463
516
|
|
464
517
|
```bash
|
465
518
|
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
466
|
-
[PD] /Users/User/project/piecemeal.rb:3
|
519
|
+
[PD] /Users/User/project/piecemeal.rb:3 in Object.<main>
|
467
520
|
> pd data, header: true
|
468
521
|
=> [1, [2, 3]]
|
469
522
|
```
|
@@ -481,7 +534,7 @@ Prints out:
|
|
481
534
|
```bash
|
482
535
|
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
483
536
|
-<[PD]>-
|
484
|
-
/Users/User/project/piecemeal.rb:3
|
537
|
+
/Users/User/project/piecemeal.rb:3 in Object.<main>
|
485
538
|
> pd data, header: '>'*80, footer: '<'*80, announcer: " -<[PD]>-\n "
|
486
539
|
=> [1, [2, 3]]
|
487
540
|
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
@@ -505,16 +558,16 @@ Example:
|
|
505
558
|
```ruby
|
506
559
|
# /Users/User/finance_calculator_app/pd_test.rb # line 1
|
507
560
|
PutsDebuggerer.app_path = File.join('/Users', 'User', 'finance_calculator_app') # line 2
|
508
|
-
bug = '
|
561
|
+
bug = 'Beetle' # line 3
|
509
562
|
pd "Show me the source of the bug: #{bug}" # line 4
|
510
563
|
```
|
511
564
|
|
512
565
|
Example Printout:
|
513
566
|
|
514
567
|
```bash
|
515
|
-
[PD] /pd_test.rb:4
|
568
|
+
[PD] /pd_test.rb:4 in Object.<main>
|
516
569
|
> pd "Show me the source of the bug: #{bug}"
|
517
|
-
=> "Show me the source of the bug:
|
570
|
+
=> "Show me the source of the bug: Beetle"
|
518
571
|
```
|
519
572
|
|
520
573
|
#### `PutsDebuggerer.header`
|
@@ -536,7 +589,7 @@ Prints out:
|
|
536
589
|
|
537
590
|
```bash
|
538
591
|
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
539
|
-
[PD] /Users/User/example.rb:1
|
592
|
+
[PD] /Users/User/example.rb:1 in Object.<main>
|
540
593
|
> pd (x=1), header: true
|
541
594
|
=> "1"
|
542
595
|
```
|
@@ -551,7 +604,7 @@ Prints out:
|
|
551
604
|
|
552
605
|
```bash
|
553
606
|
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
554
|
-
[PD] /Users/User/example.rb:1
|
607
|
+
[PD] /Users/User/example.rb:1 in Object.<main>
|
555
608
|
> pd (x=1), h: :t
|
556
609
|
=> "1"
|
557
610
|
```
|
@@ -568,11 +621,11 @@ Prints out:
|
|
568
621
|
|
569
622
|
```bash
|
570
623
|
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
571
|
-
[PD] /Users/User/example.rb:2
|
624
|
+
[PD] /Users/User/example.rb:2 in Object.<main>
|
572
625
|
> pd (x=1)
|
573
626
|
=> "1"
|
574
627
|
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
575
|
-
[PD] /Users/User/example.rb:3
|
628
|
+
[PD] /Users/User/example.rb:3 in Object.<main>
|
576
629
|
> pd (x=2)
|
577
630
|
=> "2"
|
578
631
|
```
|
@@ -595,7 +648,7 @@ pd (x=1), footer: true
|
|
595
648
|
Prints out:
|
596
649
|
|
597
650
|
```bash
|
598
|
-
[PD] /Users/User/example.rb:1
|
651
|
+
[PD] /Users/User/example.rb:1 in Object.<main>
|
599
652
|
> pd (x=1), footer: true
|
600
653
|
=> "1"
|
601
654
|
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
@@ -610,7 +663,7 @@ pd (x=1), f: :t
|
|
610
663
|
Prints out:
|
611
664
|
|
612
665
|
```bash
|
613
|
-
[PD] /Users/User/example.rb:1
|
666
|
+
[PD] /Users/User/example.rb:1 in Object.<main>
|
614
667
|
> pd (x=1), f: :t
|
615
668
|
=> "1"
|
616
669
|
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
@@ -627,11 +680,11 @@ pd (x=2)
|
|
627
680
|
Prints out:
|
628
681
|
|
629
682
|
```bash
|
630
|
-
[PD] /Users/User/example.rb:2
|
683
|
+
[PD] /Users/User/example.rb:2 in Object.<main>
|
631
684
|
> pd (x=1)
|
632
685
|
=> "1"
|
633
686
|
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
634
|
-
[PD] /Users/User/example.rb:3
|
687
|
+
[PD] /Users/User/example.rb:3 in Object.<main>
|
635
688
|
> pd (x=2)
|
636
689
|
=> "2"
|
637
690
|
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
@@ -656,7 +709,7 @@ Prints out:
|
|
656
709
|
|
657
710
|
```bash
|
658
711
|
********************************************************************************
|
659
|
-
[PD] /Users/User/example.rb:1
|
712
|
+
[PD] /Users/User/example.rb:1 in Object.<main>
|
660
713
|
> pd x=1, wrapper: true
|
661
714
|
=> "1"
|
662
715
|
********************************************************************************
|
@@ -672,7 +725,7 @@ Prints out:
|
|
672
725
|
|
673
726
|
```bash
|
674
727
|
********************************************************************************
|
675
|
-
[PD] /Users/User/example.rb:1
|
728
|
+
[PD] /Users/User/example.rb:1 in Object.<main>
|
676
729
|
> pd x=1, w: :t
|
677
730
|
=> "1"
|
678
731
|
********************************************************************************
|
@@ -690,12 +743,12 @@ Prints out:
|
|
690
743
|
|
691
744
|
```bash
|
692
745
|
********************************************************************************
|
693
|
-
[PD] /Users/User/example.rb:2
|
746
|
+
[PD] /Users/User/example.rb:2 in Object.<main>
|
694
747
|
> pd (x=1)
|
695
748
|
=> "1"
|
696
749
|
********************************************************************************
|
697
750
|
********************************************************************************
|
698
|
-
[PD] /Users/User/example.rb:3
|
751
|
+
[PD] /Users/User/example.rb:3 in Object.<main>
|
699
752
|
> pd (x=2)
|
700
753
|
=> "2"
|
701
754
|
********************************************************************************
|
@@ -716,7 +769,7 @@ pd (true ||
|
|
716
769
|
Prints out:
|
717
770
|
|
718
771
|
```
|
719
|
-
[PD] /Users/User/example.rb:1
|
772
|
+
[PD] /Users/User/example.rb:1 in Object.<main>
|
720
773
|
> pd (true ||
|
721
774
|
false), source_line_count: 2
|
722
775
|
=> "true"
|
@@ -733,7 +786,7 @@ pd (true ||
|
|
733
786
|
Prints out:
|
734
787
|
|
735
788
|
```
|
736
|
-
[PD] /Users/User/example.rb:2
|
789
|
+
[PD] /Users/User/example.rb:2 in Object.<main>
|
737
790
|
> pd (true ||
|
738
791
|
false), source_line_count: 2
|
739
792
|
=> "true"
|
@@ -787,12 +840,14 @@ Prints out the following in standard out stream only (not in log files):
|
|
787
840
|
|
788
841
|
Print engine is similar to `printer`, except it is focused on the scope of formatting
|
789
842
|
the data object being printed (excluding metadata such as file name, line number,
|
790
|
-
and expression, which are handled by the `printer`).
|
843
|
+
class name, method name, and expression, which are handled by the `printer`).
|
791
844
|
As such, it is also a global method symbol or lambda expression.
|
792
845
|
Examples of global methods are `:p`, `:ap`, and `:pp`.
|
793
846
|
An example of a lambda expression is `lambda {|object| puts object.to_a.join(" | ")}`
|
794
847
|
|
795
|
-
Defaults to [awesome_print](https://github.com/awesome-print/awesome_print).
|
848
|
+
Defaults to [awesome_print](https://github.com/awesome-print/awesome_print). It does not load the library however until the first use of the `pd` command.
|
849
|
+
|
850
|
+
If you want to avoid loading [awesome_print](https://github.com/awesome-print/awesome_print) to use an alternative instead like [amazing_print](https://github.com/amazing-print/amazing_print), make sure to load [amazing_print](https://github.com/amazing-print/amazing_print) and call `PutsDebuggerer.print_engine = :ap` before the first `pd` call ([amazing_print](https://github.com/amazing-print/amazing_print) works through `ap` just like [awesome_print](https://github.com/awesome-print/awesome_print)).
|
796
851
|
|
797
852
|
Example:
|
798
853
|
|
@@ -806,7 +861,7 @@ pd array
|
|
806
861
|
Prints out:
|
807
862
|
|
808
863
|
```bash
|
809
|
-
[PD] /Users/User/example.rb:4
|
864
|
+
[PD] /Users/User/example.rb:4 in Object.<main>
|
810
865
|
> pd array
|
811
866
|
=> [1, [2, 3]]
|
812
867
|
```
|
@@ -827,7 +882,7 @@ Prints out:
|
|
827
882
|
|
828
883
|
```bash
|
829
884
|
*** PD ***
|
830
|
-
/Users/User/example.rb:2
|
885
|
+
/Users/User/example.rb:2 in Object.<main>
|
831
886
|
> pd x=1
|
832
887
|
=> "1"
|
833
888
|
```
|
@@ -837,15 +892,17 @@ Prints out:
|
|
837
892
|
|
838
893
|
Formatter used in every print out
|
839
894
|
Passed a data argument with the following keys:
|
840
|
-
*
|
841
|
-
*
|
842
|
-
*
|
843
|
-
*
|
844
|
-
*
|
845
|
-
*
|
846
|
-
*
|
847
|
-
*
|
848
|
-
*
|
895
|
+
* `:announcer` (`String`)
|
896
|
+
* `:caller` (`Array`)
|
897
|
+
* `:class` (`String`)
|
898
|
+
* `:file` (`String`)
|
899
|
+
* `:footer` (`String`)
|
900
|
+
* `:header` (`String`)
|
901
|
+
* `:line_number` (`String`)
|
902
|
+
* `:method` (`String`)
|
903
|
+
* `:pd_expression` (`String`)
|
904
|
+
* `:object` (`Object`)
|
905
|
+
* `:object_printer` (`Proc`)
|
849
906
|
|
850
907
|
NOTE: data for :object_printer is not a string, yet a proc that must
|
851
908
|
be called to output value. It is a proc as it automatically handles usage
|
@@ -860,6 +917,8 @@ PutsDebuggerer.formatter = -> (data) {
|
|
860
917
|
puts "HEADER: #{data[:header]}"
|
861
918
|
puts "FILE: #{data[:file]}"
|
862
919
|
puts "LINE: #{data[:line_number]}"
|
920
|
+
puts "CLASS: #{data[:class]}"
|
921
|
+
puts "METHOD: #{data[:method]}"
|
863
922
|
puts "EXPRESSION: #{data[:pd_expression]}"
|
864
923
|
print "PRINT OUT: "
|
865
924
|
data[:object_printer].call
|
@@ -873,9 +932,11 @@ Prints out:
|
|
873
932
|
|
874
933
|
```bash
|
875
934
|
-<[PD]>-
|
876
|
-
FILE: /Users/User/example.rb
|
877
935
|
HEADER: ********************************************************************************
|
936
|
+
FILE: /Users/User/example.rb
|
878
937
|
LINE: 9
|
938
|
+
CLASS: Example
|
939
|
+
METHOD: test
|
879
940
|
EXPRESSION: x=1
|
880
941
|
PRINT OUT: 1
|
881
942
|
CALLER: #/Users/User/master_examples.rb:83:in `block (3 levels) in <top (required)>'
|
@@ -895,15 +956,17 @@ Example:
|
|
895
956
|
|
896
957
|
```ruby
|
897
958
|
# File Name: /Users/User/sample_app/lib/sample.rb
|
898
|
-
|
959
|
+
class Sample
|
960
|
+
pd (x=1), caller: 3
|
961
|
+
end
|
899
962
|
```
|
900
963
|
|
901
964
|
Prints out (fictional):
|
902
965
|
|
903
966
|
```bash
|
904
|
-
[PD] /Users/User/sample_app/lib/sample.rb:
|
967
|
+
[PD] /Users/User/sample_app/lib/sample.rb:3 in Sample.<class:Sample>
|
905
968
|
> pd x=1, caller: 3
|
906
|
-
=>
|
969
|
+
=> 1
|
907
970
|
/Users/User/sample_app/lib/master_samples.rb:368:in \`block (3 levels) in <top (required)>\'
|
908
971
|
/Users/User/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/irb/workspace.rb:87:in \`eval\'
|
909
972
|
/Users/User/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/irb/workspace.rb:87:in \`evaluate\'
|
@@ -914,15 +977,17 @@ Shortcut Example:
|
|
914
977
|
|
915
978
|
```ruby
|
916
979
|
# File Name: /Users/User/sample_app/lib/sample.rb
|
917
|
-
|
980
|
+
class Sample
|
981
|
+
pd (x=1), c: 3
|
982
|
+
end
|
918
983
|
```
|
919
984
|
|
920
985
|
Prints out (fictional):
|
921
986
|
|
922
987
|
```bash
|
923
|
-
[PD] /Users/User/sample_app/lib/sample.rb:
|
988
|
+
[PD] /Users/User/sample_app/lib/sample.rb:3 in Sample.<class:Sample>
|
924
989
|
> pd x=1, caller: 3
|
925
|
-
=>
|
990
|
+
=> 1
|
926
991
|
/Users/User/sample_app/lib/master_samples.rb:368:in \`block (3 levels) in <top (required)>\'
|
927
992
|
/Users/User/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/irb/workspace.rb:87:in \`eval\'
|
928
993
|
/Users/User/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/irb/workspace.rb:87:in \`evaluate\'
|
@@ -934,23 +999,30 @@ Global Option Example:
|
|
934
999
|
```ruby
|
935
1000
|
# File Name: /Users/User/sample_app/lib/sample.rb
|
936
1001
|
PutsDebuggerer.caller = 3 # always print 3 lines only of the stack trace
|
937
|
-
|
938
|
-
|
1002
|
+
class Sample
|
1003
|
+
class << self
|
1004
|
+
def test
|
1005
|
+
pd (x=1)
|
1006
|
+
pd (x=2)
|
1007
|
+
end
|
1008
|
+
end
|
1009
|
+
end
|
1010
|
+
Sample.test
|
939
1011
|
```
|
940
1012
|
|
941
1013
|
Prints out:
|
942
1014
|
|
943
1015
|
```bash
|
944
|
-
[PD] /Users/User/sample_app/lib/sample.rb:
|
1016
|
+
[PD] /Users/User/sample_app/lib/sample.rb:6 in Sample.test
|
945
1017
|
> pd (x=1)
|
946
|
-
=>
|
1018
|
+
=> 1
|
947
1019
|
/Users/User/sample_app/lib/master_samples.rb:368:in \`block (3 levels) in <top (required)>\'
|
948
1020
|
/Users/User/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/irb/workspace.rb:87:in \`eval\'
|
949
1021
|
/Users/User/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/irb/workspace.rb:87:in \`evaluate\'
|
950
1022
|
/Users/User/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/irb/context.rb:381:in \`evaluate\'
|
951
|
-
[PD] /Users/User/sample_app/lib/sample.rb:
|
1023
|
+
[PD] /Users/User/sample_app/lib/sample.rb:7 in Sample.test
|
952
1024
|
> pd (x=2)
|
953
|
-
=>
|
1025
|
+
=> 2
|
954
1026
|
/Users/User/sample_app/lib/master_samples.rb:368:in \`block (3 levels) in <top (required)>\'
|
955
1027
|
/Users/User/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/irb/workspace.rb:87:in \`eval\'
|
956
1028
|
/Users/User/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/irb/workspace.rb:87:in \`evaluate\'
|
@@ -1122,4 +1194,4 @@ Note that it ignores the configured printer when printing exceptions as it relie
|
|
1122
1194
|
|
1123
1195
|
[MIT](LICENSE.txt)
|
1124
1196
|
|
1125
|
-
Copyright (c) 2017-
|
1197
|
+
Copyright (c) 2017-2024 - Andy Maleh.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
1.0.1
|
data/lib/pd.rb
CHANGED
@@ -143,6 +143,12 @@ module Kernel
|
|
143
143
|
caller[caller_depth] && caller[caller_depth][regex, 1]
|
144
144
|
end
|
145
145
|
|
146
|
+
# Provides caller method starting 1 level above caller of
|
147
|
+
# this method.
|
148
|
+
def __caller_method__(caller_depth=0)
|
149
|
+
regex = PutsDebuggerer::STACK_TRACE_CALL_METHOD_REGEX
|
150
|
+
caller[caller_depth] && caller[caller_depth][regex, 1]
|
151
|
+
end
|
146
152
|
|
147
153
|
# Provides caller source line starting 1 level above caller of
|
148
154
|
# this method.
|
@@ -189,6 +195,8 @@ module Kernel
|
|
189
195
|
pd_data = {
|
190
196
|
announcer: PutsDebuggerer.announcer,
|
191
197
|
file: __caller_file__(depth)&.sub(PutsDebuggerer.app_path.to_s, ''),
|
198
|
+
class: self.is_a?(Module) ? self : self.class,
|
199
|
+
method: __caller_method__(depth)&.sub(PutsDebuggerer.app_path.to_s, ''),
|
192
200
|
line_number: __caller_line_number__(depth),
|
193
201
|
pd_expression: __caller_pd_expression__(depth, source_line_count),
|
194
202
|
run_number: run_number,
|
data/lib/puts_debuggerer.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.expand_path(__dir__)) unless $LOAD_PATH.include?(File.expand_path(__dir__))
|
2
|
+
|
1
3
|
require 'puts_debuggerer/core_ext/kernel'
|
2
4
|
require 'puts_debuggerer/core_ext/logger'
|
3
5
|
require 'puts_debuggerer/core_ext/logging/logger'
|
@@ -52,7 +54,7 @@ module PutsDebuggerer
|
|
52
54
|
FORMATTER_DEFAULT = -> (data) {
|
53
55
|
puts data[:wrapper] if data[:wrapper]
|
54
56
|
puts data[:header] if data[:header]
|
55
|
-
print "#{data[:announcer]} #{data[:file]}#{':' if data[:line_number]}#{data[:line_number]}#{" (run:#{data[:run_number]})" if data[:run_number]}#{__format_pd_expression__(data[:pd_expression], data[:object])} "
|
57
|
+
print "#{data[:announcer]} #{data[:file]}#{':' if data[:line_number]}#{data[:line_number]} in #{[data[:class], data[:method]].compact.join('.')}#{" (run:#{data[:run_number]})" if data[:run_number]}#{__format_pd_expression__(data[:pd_expression], data[:object])} "
|
56
58
|
data[:object_printer].call
|
57
59
|
puts data[:caller].map {|l| ' ' + l} unless data[:caller].to_a.empty?
|
58
60
|
puts data[:footer] if data[:footer]
|
@@ -63,6 +65,7 @@ module PutsDebuggerer
|
|
63
65
|
STACK_TRACE_CALL_LINE_NUMBER_REGEX = /\:(\d+)\:in /
|
64
66
|
STACK_TRACE_CALL_SOURCE_FILE_REGEX = /[ ]*([^:]+)\:\d+\:in /
|
65
67
|
STACK_TRACE_CALL_SOURCE_FILE_REGEX_OPAL = /(http[^\)]+)/
|
68
|
+
STACK_TRACE_CALL_METHOD_REGEX = /`([^']+)'$/
|
66
69
|
OPTIONS = [:app_path, :source_line_count, :header, :h, :wrapper, :w, :footer, :f, :printer, :print_engine, :announcer, :formatter, :caller, :run_at]
|
67
70
|
OPTION_ALIASES = {
|
68
71
|
a: :announcer,
|
@@ -481,9 +484,7 @@ module PutsDebuggerer
|
|
481
484
|
convert_options(objects.delete_at(-1))
|
482
485
|
elsif objects.size == 1 && objects.first.is_a?(Hash)
|
483
486
|
hash = objects.first
|
484
|
-
convert_options(hash.slice(*OPTIONS)
|
485
|
-
hash.delete_if {|option| OPTIONS.include?(option)}
|
486
|
-
end)
|
487
|
+
convert_options(hash.slice(*OPTIONS))
|
487
488
|
end
|
488
489
|
end
|
489
490
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puts_debuggerer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Maleh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-06-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: awesome_print
|
@@ -94,48 +94,6 @@ dependencies:
|
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: 2.1.4
|
97
|
-
- !ruby/object:Gem::Dependency
|
98
|
-
name: coveralls
|
99
|
-
requirement: !ruby/object:Gem::Requirement
|
100
|
-
requirements:
|
101
|
-
- - '='
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
version: 0.8.23
|
104
|
-
type: :development
|
105
|
-
prerelease: false
|
106
|
-
version_requirements: !ruby/object:Gem::Requirement
|
107
|
-
requirements:
|
108
|
-
- - '='
|
109
|
-
- !ruby/object:Gem::Version
|
110
|
-
version: 0.8.23
|
111
|
-
- !ruby/object:Gem::Dependency
|
112
|
-
name: simplecov
|
113
|
-
requirement: !ruby/object:Gem::Requirement
|
114
|
-
requirements:
|
115
|
-
- - "~>"
|
116
|
-
- !ruby/object:Gem::Version
|
117
|
-
version: 0.16.1
|
118
|
-
type: :development
|
119
|
-
prerelease: false
|
120
|
-
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
requirements:
|
122
|
-
- - "~>"
|
123
|
-
- !ruby/object:Gem::Version
|
124
|
-
version: 0.16.1
|
125
|
-
- !ruby/object:Gem::Dependency
|
126
|
-
name: simplecov-lcov
|
127
|
-
requirement: !ruby/object:Gem::Requirement
|
128
|
-
requirements:
|
129
|
-
- - "~>"
|
130
|
-
- !ruby/object:Gem::Version
|
131
|
-
version: 0.7.0
|
132
|
-
type: :development
|
133
|
-
prerelease: false
|
134
|
-
version_requirements: !ruby/object:Gem::Requirement
|
135
|
-
requirements:
|
136
|
-
- - "~>"
|
137
|
-
- !ruby/object:Gem::Version
|
138
|
-
version: 0.7.0
|
139
97
|
- !ruby/object:Gem::Dependency
|
140
98
|
name: logging
|
141
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -166,7 +124,7 @@ dependencies:
|
|
166
124
|
version: '0'
|
167
125
|
description: |
|
168
126
|
Debuggers are great! They help us troubleshoot complicated programming problems by inspecting values produced by code, line by line. They are invaluable when trying to understand what is going on in a large application composed of thousands or millions of lines of code.
|
169
|
-
In day-to-day test-driven development and simple debugging though, a puts statement can be a lot quicker in revealing what is going on than halting execution completely just to inspect a single value or a few. This is certainly true when writing the simplest possible code that could possibly work, and running a test every few seconds or minutes. Problem is you need to locate puts statements in large output logs, know which methods
|
127
|
+
In day-to-day test-driven development and simple debugging though, a puts statement can be a lot quicker in revealing what is going on than halting execution completely just to inspect a single value or a few. This is certainly true when writing the simplest possible code that could possibly work, and running a test every few seconds or minutes. Problem is you need to locate puts statements in large output logs, know which file names, line numbers, classes, and methods contained the puts statements, find out what variable names are being printed, and see nicely formatted output. Enter puts_debuggerer. A guilt-free puts debugging Ruby gem FTW that prints file names, line numbers, class names, method names, and code statements; and formats output nicely courtesy of awesome_print.
|
170
128
|
Partially inspired by this blog post: https://tenderlovemaking.com/2016/02/05/i-am-a-puts-debuggerer.html (Credit to Tenderlove.)
|
171
129
|
email: andy.am@gmail.com
|
172
130
|
executables: []
|
@@ -206,9 +164,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
206
164
|
- !ruby/object:Gem::Version
|
207
165
|
version: '0'
|
208
166
|
requirements: []
|
209
|
-
rubygems_version: 3.3
|
167
|
+
rubygems_version: 3.5.3
|
210
168
|
signing_key:
|
211
169
|
specification_version: 4
|
212
170
|
summary: Ruby library for improved puts debugging, automatically displaying bonus
|
213
|
-
useful information such as source line number
|
171
|
+
useful information such as source file name, line number, class name, method name,
|
172
|
+
and source code.
|
214
173
|
test_files: []
|