puts_debuggerer 0.10.2 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +45 -57
- data/VERSION +1 -1
- data/lib/puts_debuggerer.rb +15 -11
- data/lib/puts_debuggerer/core_ext/kernel.rb +40 -33
- data/lib/puts_debuggerer/run_determiner.rb +7 -7
- data/lib/puts_debuggerer/source_file.rb +4 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 43ff23befa76e5fc66ff64e550594c4e0c4a2055d586329ee731c075c6ab54a7
|
4
|
+
data.tar.gz: 1224fadbcca6b036eac9ed58d9ce60d5e7f7a6cd3a6742de05e4f82cb9107b8e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 13af30103a2bfa13e3e579f9083ed366fb4fa168e53a7c685e9181c60fb194dc24430e49d14348d4ae59f7573430b1f665987182b101a4a5da28394acf9b485e
|
7
|
+
data.tar.gz: 3b6eb47ca8c5758f3ffe6405ca94031bc05ee2cfad09cbb1f20fec85aea0fef42c0900a9ccd43916f4f567aed1d7c8f5ec9ec779c69c586cd9f5052e8b809047
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## 0.11.0
|
4
|
+
|
5
|
+
- Pry support
|
6
|
+
- In Opal, print exceptions as errors in the web console using an alternative to full_message since it's not implemented in Opal yet
|
7
|
+
- Fix `pd_inspect` and `pdi` in IRB
|
8
|
+
|
3
9
|
## 0.10.2
|
4
10
|
|
5
11
|
- Improve Opal Ruby compatibility by displaying source file/line
|
data/README.md
CHANGED
@@ -12,7 +12,7 @@ In day-to-day test-driven development and simple app debugging though, a puts st
|
|
12
12
|
|
13
13
|
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, and formats output nicely courtesy of [awesome_print](https://rubygems.org/gems/awesome_print).
|
14
14
|
|
15
|
-
[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.
|
15
|
+
[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).
|
16
16
|
|
17
17
|
Basic Example:
|
18
18
|
|
@@ -62,28 +62,6 @@ Which gets lost in a logging stream such as:
|
|
62
62
|
(0.2ms) COMMIT
|
63
63
|
```
|
64
64
|
|
65
|
-
Problem can be mitigated by adding a few more puts statements:
|
66
|
-
|
67
|
-
```ruby
|
68
|
-
puts "*"*40
|
69
|
-
puts "order_total"
|
70
|
-
puts order_total
|
71
|
-
```
|
72
|
-
|
73
|
-
But those add up pretty quickly when inspecting multiple variables:
|
74
|
-
|
75
|
-
```ruby
|
76
|
-
puts "*"*40
|
77
|
-
puts "order_total"
|
78
|
-
puts order_total
|
79
|
-
puts "*"*40
|
80
|
-
puts "order_summary"
|
81
|
-
puts order_summary
|
82
|
-
puts "*"*40
|
83
|
-
puts "order_details"
|
84
|
-
puts order_details
|
85
|
-
```
|
86
|
-
|
87
65
|
Here is a simple example using `pd` instead, which provides everything the puts statements above provide in addition to deducing the file name and line number automatically for dead easy debugging:
|
88
66
|
|
89
67
|
```ruby
|
@@ -93,9 +71,17 @@ pd order_total
|
|
93
71
|
Output:
|
94
72
|
|
95
73
|
```
|
74
|
+
(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)
|
75
|
+
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]]
|
76
|
+
(0.2ms) BEGIN
|
77
|
+
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]]
|
78
|
+
(0.3ms) COMMIT
|
96
79
|
[PD] /Users/User/ordering/order.rb:39
|
97
|
-
> pd order_total
|
80
|
+
> pd order_total
|
98
81
|
=> 195.50
|
82
|
+
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]]
|
83
|
+
(0.2ms) BEGIN
|
84
|
+
(0.2ms) COMMIT
|
99
85
|
```
|
100
86
|
|
101
87
|
This is not only easy to locate in a logging stream such as the one below, but also announces the `order_total` variable with `[PD]` for easy findability among other pd statements (you may always enter `[PD]` or variable name `order_total` using the CMD+F Quick Find to instantly jump to that line in the log):
|
@@ -112,23 +98,23 @@ Output:
|
|
112
98
|
(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)
|
113
99
|
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]]
|
114
100
|
[PD] /Users/User/ordering/order.rb:39
|
115
|
-
> pd order_total
|
101
|
+
> pd order_total
|
116
102
|
=> 195.50
|
117
103
|
(0.2ms) BEGIN
|
118
104
|
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]]
|
119
105
|
(0.3ms) COMMIT
|
120
106
|
[PD] /Users/User/ordering/order.rb:40
|
121
|
-
> pd order_summary
|
107
|
+
> pd order_summary
|
122
108
|
=> "Pragmatic Ruby Book"
|
123
109
|
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]]
|
124
110
|
(0.2ms) BEGIN
|
125
111
|
(0.2ms) COMMIT
|
126
112
|
[PD] /Users/User/ordering/order.rb:41
|
127
|
-
> pd order_details
|
113
|
+
> pd order_details
|
128
114
|
=> "[Hard Cover] Pragmatic Ruby Book - English Version"
|
129
115
|
```
|
130
116
|
|
131
|
-
What if you would like to add a header for faster findability? Just use the `header` option:
|
117
|
+
What if you would like to add a header for faster findability of groups of related pd statements? Just use the `header` option:
|
132
118
|
|
133
119
|
```ruby
|
134
120
|
pd order_total, header: true
|
@@ -141,7 +127,7 @@ Output:
|
|
141
127
|
```
|
142
128
|
(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)
|
143
129
|
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]]
|
144
|
-
|
130
|
+
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
145
131
|
[PD] /Users/User/ordering/order.rb:39
|
146
132
|
> pd order_total, header: true
|
147
133
|
=> 195.50
|
@@ -149,13 +135,13 @@ Output:
|
|
149
135
|
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]]
|
150
136
|
(0.3ms) COMMIT
|
151
137
|
[PD] /Users/User/ordering/order.rb:40
|
152
|
-
> pd order_summary
|
138
|
+
> pd order_summary
|
153
139
|
=> "Pragmatic Ruby Book"
|
154
140
|
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]]
|
155
141
|
(0.2ms) BEGIN
|
156
142
|
(0.2ms) COMMIT
|
157
143
|
[PD] /Users/User/ordering/order.rb:41
|
158
|
-
> pd order_details
|
144
|
+
> pd order_details
|
159
145
|
=> "[Hard Cover] Pragmatic Ruby Book - English Version"
|
160
146
|
```
|
161
147
|
|
@@ -180,13 +166,13 @@ Output:
|
|
180
166
|
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]]
|
181
167
|
(0.3ms) COMMIT
|
182
168
|
[PD] /Users/User/ordering/order.rb:40
|
183
|
-
> pd order_summary
|
169
|
+
> pd order_summary
|
184
170
|
=> "Pragmatic Ruby Book"
|
185
171
|
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]]
|
186
172
|
(0.2ms) BEGIN
|
187
173
|
(0.2ms) COMMIT
|
188
174
|
[PD] /Users/User/ordering/order.rb:41
|
189
|
-
> pd order_details, footer: '<'*80
|
175
|
+
> pd order_details, footer: '<'*80
|
190
176
|
=> "[Hard Cover] Pragmatic Ruby Book - English Version"
|
191
177
|
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
192
178
|
```
|
@@ -250,13 +236,13 @@ Output:
|
|
250
236
|
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]]
|
251
237
|
(0.3ms) COMMIT
|
252
238
|
[PD] /Users/User/ordering/order.rb:40
|
253
|
-
> pd order_summary
|
239
|
+
> pd order_summary
|
254
240
|
=> "Pragmatic Ruby Book"
|
255
241
|
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]]
|
256
242
|
(0.2ms) BEGIN
|
257
243
|
(0.2ms) COMMIT
|
258
244
|
[PD] /Users/User/ordering/order.rb:41
|
259
|
-
> pd order_details
|
245
|
+
> pd order_details
|
260
246
|
=> "[Hard Cover] Pragmatic Ruby Book - English Version"
|
261
247
|
```
|
262
248
|
|
@@ -273,7 +259,7 @@ pd order_details
|
|
273
259
|
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]]
|
274
260
|
********************************************************************************
|
275
261
|
[PD] /Users/User/ordering/order.rb:39
|
276
|
-
> pd order_total, caller: 3, wrapper: true
|
262
|
+
> pd order_total, caller: 3, wrapper: true
|
277
263
|
=> 195.50
|
278
264
|
/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'
|
279
265
|
/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 `block in require_with_bootsnap_lfi'
|
@@ -283,13 +269,13 @@ pd order_details
|
|
283
269
|
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]]
|
284
270
|
(0.3ms) COMMIT
|
285
271
|
[PD] /Users/User/ordering/order.rb:40
|
286
|
-
> pd order_summary
|
272
|
+
> pd order_summary
|
287
273
|
=> "Pragmatic Ruby Book"
|
288
274
|
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]]
|
289
275
|
(0.2ms) BEGIN
|
290
276
|
(0.2ms) COMMIT
|
291
277
|
[PD] /Users/User/ordering/order.rb:41
|
292
|
-
> pd order_details
|
278
|
+
> pd order_details
|
293
279
|
=> "[Hard Cover] Pragmatic Ruby Book - English Version"
|
294
280
|
```
|
295
281
|
|
@@ -302,7 +288,7 @@ There are many more options and powerful features in [puts_debuggerer](https://r
|
|
302
288
|
Add the following to bundler's `Gemfile`.
|
303
289
|
|
304
290
|
```ruby
|
305
|
-
gem 'puts_debuggerer', '~> 0.10.
|
291
|
+
gem 'puts_debuggerer', '~> 0.10.3'
|
306
292
|
```
|
307
293
|
|
308
294
|
This is the recommended way for [Rails](rubyonrails.org) apps. Optionally, you may create an initializer under `config/initializers` named `puts_debuggerer_options.rb` to enable further customizations as per the [Options](#options) section below.
|
@@ -312,7 +298,7 @@ This is the recommended way for [Rails](rubyonrails.org) apps. Optionally, you m
|
|
312
298
|
Or manually install and require library.
|
313
299
|
|
314
300
|
```bash
|
315
|
-
gem install puts_debuggerer -v0.10.
|
301
|
+
gem install puts_debuggerer -v0.10.3
|
316
302
|
```
|
317
303
|
|
318
304
|
```ruby
|
@@ -371,7 +357,7 @@ Output:
|
|
371
357
|
=> "Show me the result of the calculation: 4.0"
|
372
358
|
```
|
373
359
|
|
374
|
-
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).
|
360
|
+
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 and Pry).
|
375
361
|
|
376
362
|
Second, quickly locate printed lines using the Find feature (e.g. CTRL+F) by looking for:
|
377
363
|
* [PD]
|
@@ -405,14 +391,14 @@ Happy puts_debuggerering!
|
|
405
391
|
You may want to just return the string produced by the `pd` method without printing it.
|
406
392
|
|
407
393
|
In that case, you may use the `pd` alternative to `object.inspect`:
|
408
|
-
- `object.pd_inspect`
|
394
|
+
- `object.pd_inspect`
|
409
395
|
- `obj.pdi` (shorter alias)
|
410
396
|
|
411
397
|
This returns the `pd` formatted string without printing to the terminal or log files.
|
412
398
|
|
413
|
-
#### Ruby Logger and Logging::Logger
|
399
|
+
#### Ruby Logger and Logging::Logger
|
414
400
|
|
415
|
-
Ruby Logger and Logging::Logger (from [logging gem](https://github.com/TwP/logging)) are supported as [printers](#putsdebuggererprinter) (learn more under [PutsDebuggerer#printer](#putsdebuggererprinter)).
|
401
|
+
Ruby Logger and Logging::Logger (from [logging gem](https://github.com/TwP/logging)) are supported as [printers](#putsdebuggererprinter) (learn more under [PutsDebuggerer#printer](#putsdebuggererprinter)).
|
416
402
|
|
417
403
|
### Options
|
418
404
|
|
@@ -436,7 +422,7 @@ pd data, header: true
|
|
436
422
|
Prints out:
|
437
423
|
|
438
424
|
```bash
|
439
|
-
|
425
|
+
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
440
426
|
[PD] /Users/User/project/piecemeal.rb:3
|
441
427
|
> pd data, header: true
|
442
428
|
=> [1, [2, 3]]
|
@@ -502,7 +488,7 @@ pd (x=1), header: true
|
|
502
488
|
Prints out:
|
503
489
|
|
504
490
|
```bash
|
505
|
-
|
491
|
+
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
506
492
|
[PD] /Users/User/example.rb:1
|
507
493
|
> pd (x=1), header: true
|
508
494
|
=> "1"
|
@@ -519,11 +505,11 @@ pd (x=2)
|
|
519
505
|
Prints out:
|
520
506
|
|
521
507
|
```bash
|
522
|
-
|
508
|
+
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
523
509
|
[PD] /Users/User/example.rb:2
|
524
510
|
> pd (x=1)
|
525
511
|
=> "1"
|
526
|
-
|
512
|
+
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
527
513
|
[PD] /Users/User/example.rb:3
|
528
514
|
> pd (x=2)
|
529
515
|
=> "2"
|
@@ -550,7 +536,7 @@ Prints out:
|
|
550
536
|
[PD] /Users/User/example.rb:1
|
551
537
|
> pd (x=1), footer: true
|
552
538
|
=> "1"
|
553
|
-
|
539
|
+
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
554
540
|
```
|
555
541
|
|
556
542
|
Global Option Example:
|
@@ -567,11 +553,11 @@ Prints out:
|
|
567
553
|
[PD] /Users/User/example.rb:2
|
568
554
|
> pd (x=1)
|
569
555
|
=> "1"
|
570
|
-
|
556
|
+
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
571
557
|
[PD] /Users/User/example.rb:3
|
572
558
|
> pd (x=2)
|
573
559
|
=> "2"
|
574
|
-
|
560
|
+
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
575
561
|
```
|
576
562
|
|
577
563
|
#### `PutsDebuggerer.wrapper`
|
@@ -625,7 +611,7 @@ Prints out:
|
|
625
611
|
#### `PutsDebuggerer.source_line_count`
|
626
612
|
(default = `1`)
|
627
613
|
|
628
|
-
Prints multiple source code lines as per count specified. Useful when a statement is broken down on multiple lines or when there is a need to get more context around the line printed.
|
614
|
+
Prints multiple source code lines as per count specified. Useful when a statement is broken down on multiple lines or when there is a need to get more context around the line printed.
|
629
615
|
|
630
616
|
Example:
|
631
617
|
|
@@ -669,7 +655,7 @@ Examples of a global method are `:puts` and `:print`.
|
|
669
655
|
An example of a lambda expression is `lambda {|output| Rails.logger.info(output)}`
|
670
656
|
Examples of a logger are a Ruby `Logger` instance or `Logging::Logger` instance
|
671
657
|
|
672
|
-
When a logger is supplied, it is automatically enhanced with a PutsDebuggerer formatter to use
|
658
|
+
When a logger is supplied, it is automatically enhanced with a PutsDebuggerer formatter to use
|
673
659
|
when calling logger methods outside of PutsDebuggerer (e.g. `logger.error('msg')` will use `pd`)
|
674
660
|
|
675
661
|
Printer may be set to `false` to avoid printing and only return the formatted string.
|
@@ -975,11 +961,11 @@ Prints out `puts __caller_source_line__`
|
|
975
961
|
|
976
962
|
## Compatibility
|
977
963
|
|
978
|
-
[puts_debuggerer](https://rubygems.org/gems/puts_debuggerer) is fully compatible with:
|
964
|
+
[puts_debuggerer](https://rubygems.org/gems/puts_debuggerer) is fully compatible with:
|
979
965
|
- [Ruby](https://www.ruby-lang.org/en/)
|
980
966
|
- [JRuby](https://www.jruby.org/)
|
981
|
-
- IRB
|
982
|
-
-
|
967
|
+
- IRB (including Rails Console)
|
968
|
+
- Pry
|
983
969
|
|
984
970
|
### Opal Ruby
|
985
971
|
|
@@ -993,10 +979,12 @@ Here is an example of `pd` output in Opal:
|
|
993
979
|
|
994
980
|
```
|
995
981
|
[PD] http://localhost:3000/assets/views/garderie_rainbow_daily_agenda/app_view.self-72626d75e0f68a619b1c8ad139535d799d45ab6c730d083820b790d71338e983.js?body=1:72:12
|
996
|
-
>
|
982
|
+
>
|
997
983
|
=> "body"
|
998
984
|
```
|
999
985
|
|
986
|
+
Note that it ignores the configured printer when printing exceptions as it relies on Opal's `$stderr.puts` instead to show the stack trace in the web console.
|
987
|
+
|
1000
988
|
## Change Log
|
1001
989
|
|
1002
990
|
[CHANGELOG.md](CHANGELOG.md)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.11.0
|
data/lib/puts_debuggerer.rb
CHANGED
@@ -6,9 +6,9 @@ require 'puts_debuggerer/source_file'
|
|
6
6
|
|
7
7
|
module PutsDebuggerer
|
8
8
|
SOURCE_LINE_COUNT_DEFAULT = 1
|
9
|
-
HEADER_DEFAULT = '
|
9
|
+
HEADER_DEFAULT = '>'*80
|
10
10
|
WRAPPER_DEFAULT = '*'*80
|
11
|
-
FOOTER_DEFAULT = '
|
11
|
+
FOOTER_DEFAULT = '<'*80
|
12
12
|
LOGGER_FORMATTER_DECORATOR = proc { |original_formatter|
|
13
13
|
proc { |severity, datetime, progname, msg|
|
14
14
|
original_formatter.call(severity, datetime, progname, msg.pd_inspect)
|
@@ -27,8 +27,12 @@ module PutsDebuggerer
|
|
27
27
|
RETURN_DEFAULT = true
|
28
28
|
OBJECT_PRINTER_DEFAULT = lambda do |object, print_engine_options=nil, source_line_count=nil, run_number=nil|
|
29
29
|
lambda do
|
30
|
-
if object.is_a?(Exception)
|
31
|
-
|
30
|
+
if object.is_a?(Exception)
|
31
|
+
if RUBY_ENGINE == 'opal'
|
32
|
+
object.backtrace.each { |line| puts line }
|
33
|
+
else
|
34
|
+
puts object.full_message
|
35
|
+
end
|
32
36
|
elsif PutsDebuggerer.print_engine.is_a?(Proc)
|
33
37
|
PutsDebuggerer.print_engine.call(object)
|
34
38
|
else
|
@@ -167,7 +171,7 @@ module PutsDebuggerer
|
|
167
171
|
instance_variable_set(:"@#{boundary_option}", nil)
|
168
172
|
else
|
169
173
|
instance_variable_set(:"@#{boundary_option}", value)
|
170
|
-
end
|
174
|
+
end
|
171
175
|
end
|
172
176
|
|
173
177
|
define_method("#{boundary_option}?") do
|
@@ -220,10 +224,10 @@ module PutsDebuggerer
|
|
220
224
|
end
|
221
225
|
|
222
226
|
def printer_default
|
223
|
-
Object.const_defined?(:Rails) ? PRINTER_RAILS : PRINTER_DEFAULT
|
227
|
+
Object.const_defined?(:Rails) ? PRINTER_RAILS : PRINTER_DEFAULT
|
224
228
|
end
|
225
229
|
|
226
|
-
# Logger original formatter before it was decorated with PutsDebuggerer::LOGGER_FORMATTER_DECORATOR
|
230
|
+
# Logger original formatter before it was decorated with PutsDebuggerer::LOGGER_FORMATTER_DECORATOR
|
227
231
|
# upon setting the logger as a printer.
|
228
232
|
attr_reader :logger_original_formatter
|
229
233
|
|
@@ -256,8 +260,8 @@ module PutsDebuggerer
|
|
256
260
|
# ]
|
257
261
|
def print_engine
|
258
262
|
if @print_engine.nil?
|
259
|
-
require 'awesome_print' if
|
260
|
-
@print_engine = print_engine_default
|
263
|
+
require 'awesome_print' if RUBY_ENGINE != 'opal'
|
264
|
+
@print_engine = print_engine_default
|
261
265
|
end
|
262
266
|
@print_engine
|
263
267
|
end
|
@@ -271,7 +275,7 @@ module PutsDebuggerer
|
|
271
275
|
end
|
272
276
|
|
273
277
|
def print_engine_default
|
274
|
-
Object.const_defined?(:AwesomePrint) ? PRINT_ENGINE_DEFAULT : :p
|
278
|
+
Object.const_defined?(:AwesomePrint) ? PRINT_ENGINE_DEFAULT : :p
|
275
279
|
end
|
276
280
|
|
277
281
|
# Announcer (e.g. [PD]) to announce every print out with (default: "[PD]")
|
@@ -464,7 +468,7 @@ module PutsDebuggerer
|
|
464
468
|
!!@run_at
|
465
469
|
end
|
466
470
|
|
467
|
-
def determine_options(objects)
|
471
|
+
def determine_options(objects)
|
468
472
|
objects.delete_at(-1) if objects.size > 1 && objects.last.is_a?(Hash)
|
469
473
|
end
|
470
474
|
|
@@ -49,32 +49,36 @@ module Kernel
|
|
49
49
|
PutsDebuggerer.formatter.call(formatter_pd_data)
|
50
50
|
$stdout = stdout
|
51
51
|
string = sio.string
|
52
|
-
if
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
PutsDebuggerer.printer.
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
appender.layout = original_layout
|
52
|
+
if RUBY_ENGINE == 'opal' && object.is_a?(Exception)
|
53
|
+
$stderr.puts(string)
|
54
|
+
else
|
55
|
+
if PutsDebuggerer.printer.is_a?(Proc)
|
56
|
+
PutsDebuggerer.printer.call(string)
|
57
|
+
elsif PutsDebuggerer.printer.is_a?(Logger)
|
58
|
+
logger_formatter = PutsDebuggerer.printer.formatter
|
59
|
+
begin
|
60
|
+
PutsDebuggerer.printer.formatter = PutsDebuggerer.logger_original_formatter
|
61
|
+
PutsDebuggerer.printer.debug(string)
|
62
|
+
ensure
|
63
|
+
PutsDebuggerer.printer.formatter = logger_formatter
|
64
|
+
end
|
65
|
+
elsif PutsDebuggerer.printer.is_a?(Logging::Logger)
|
66
|
+
logging_layouts = PutsDebuggerer.printer.appenders.reduce({}) do |hash, appender|
|
67
|
+
hash.merge(appender => appender.layout)
|
69
68
|
end
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
69
|
+
begin
|
70
|
+
PutsDebuggerer.logging_original_layouts.each do |appender, original_layout|
|
71
|
+
appender.layout = original_layout
|
72
|
+
end
|
73
|
+
PutsDebuggerer.printer.debug(string)
|
74
|
+
ensure
|
75
|
+
PutsDebuggerer.logging_original_layouts.each do |appender, original_layout|
|
76
|
+
appender.layout = logging_layouts[appender]
|
77
|
+
end
|
74
78
|
end
|
75
|
-
|
76
|
-
|
77
|
-
|
79
|
+
elsif PutsDebuggerer.printer != false
|
80
|
+
send(PutsDebuggerer.send(:printer), string)
|
81
|
+
end
|
78
82
|
end
|
79
83
|
end
|
80
84
|
end
|
@@ -83,7 +87,7 @@ module Kernel
|
|
83
87
|
end
|
84
88
|
|
85
89
|
# Implement caller backtrace method in Opal since it returns an empty array in Opal v1
|
86
|
-
if
|
90
|
+
if RUBY_ENGINE == 'opal'
|
87
91
|
def caller
|
88
92
|
begin
|
89
93
|
raise 'error'
|
@@ -109,7 +113,7 @@ module Kernel
|
|
109
113
|
#
|
110
114
|
# prints out `3`
|
111
115
|
def __caller_line_number__(caller_depth=0)
|
112
|
-
return if
|
116
|
+
return if RUBY_ENGINE == 'opal'
|
113
117
|
caller[caller_depth] && caller[caller_depth][PutsDebuggerer::STACK_TRACE_CALL_LINE_NUMBER_REGEX, 1].to_i
|
114
118
|
end
|
115
119
|
|
@@ -123,8 +127,8 @@ module Kernel
|
|
123
127
|
#
|
124
128
|
# prints out `lib/example.rb`
|
125
129
|
def __caller_file__(caller_depth=0)
|
126
|
-
regex =
|
127
|
-
caller[caller_depth] && caller[caller_depth][regex, 1]
|
130
|
+
regex = RUBY_ENGINE == 'opal' ? PutsDebuggerer::STACK_TRACE_CALL_SOURCE_FILE_REGEX_OPAL : PutsDebuggerer::STACK_TRACE_CALL_SOURCE_FILE_REGEX
|
131
|
+
caller[caller_depth] && caller[caller_depth][regex, 1]
|
128
132
|
end
|
129
133
|
|
130
134
|
|
@@ -140,8 +144,11 @@ module Kernel
|
|
140
144
|
source_line_number ||= __caller_line_number__(caller_depth+1)
|
141
145
|
source_file ||= __caller_file__(caller_depth+1)
|
142
146
|
source_line = ''
|
143
|
-
if
|
144
|
-
|
147
|
+
if defined?(Pry)
|
148
|
+
@pry_instance ||= Pry.new
|
149
|
+
source_line = Pry::Command::Hist.new(pry_instance: @pry_instance).call.instance_variable_get(:@buffer).split("\n")[source_line_number - 1] # TODO handle multi-lines in source_line_count
|
150
|
+
elsif defined?(IRB)
|
151
|
+
source_line = TOPLEVEL_BINDING.receiver.conf.io.line(source_line_number) # TODO handle multi-lines in source_line_count
|
145
152
|
else
|
146
153
|
source_line = PutsDebuggerer::SourceFile.new(source_file).source(source_line_count, source_line_number)
|
147
154
|
end
|
@@ -160,7 +167,7 @@ module Kernel
|
|
160
167
|
end
|
161
168
|
|
162
169
|
def __build_pd_data__(object, print_engine_options:nil, source_line_count:nil, run_number:nil, pd_inspect:false, logger_formatter_decorated:false, logging_layouts_decorated:false)
|
163
|
-
depth =
|
170
|
+
depth = RUBY_ENGINE == 'opal' ? PutsDebuggerer::CALLER_DEPTH_ZERO_OPAL : PutsDebuggerer::CALLER_DEPTH_ZERO
|
164
171
|
if pd_inspect
|
165
172
|
depth += 1
|
166
173
|
depth += 4 if logger_formatter_decorated
|
@@ -177,7 +184,7 @@ module Kernel
|
|
177
184
|
object_printer: PutsDebuggerer::OBJECT_PRINTER_DEFAULT.call(object, print_engine_options, source_line_count, run_number)
|
178
185
|
}
|
179
186
|
pd_data[:caller] = __caller_caller__(depth)
|
180
|
-
['header', 'wrapper', 'footer'].each do |boundary_option|
|
187
|
+
['header', 'wrapper', 'footer'].each do |boundary_option|
|
181
188
|
pd_data[boundary_option.to_sym] = PutsDebuggerer.send(boundary_option) if PutsDebuggerer.send("#{boundary_option}?")
|
182
189
|
end
|
183
190
|
pd_data
|
@@ -213,5 +220,5 @@ module Kernel
|
|
213
220
|
# outputs `(x=1)`
|
214
221
|
def __extract_pd_expression__(source_line)
|
215
222
|
source_line.to_s.strip
|
216
|
-
end
|
223
|
+
end
|
217
224
|
end
|
@@ -42,19 +42,19 @@ module PutsDebuggerer
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def run_number(object, run_at)
|
45
|
-
run_at_global_number || run_at_number(object, run_at)
|
46
|
-
end
|
45
|
+
run_at_global_number || run_at_number(object, run_at)
|
46
|
+
end
|
47
47
|
|
48
48
|
def run_pd?(object, run_at)
|
49
49
|
run_pd = false
|
50
50
|
if run_at.nil?
|
51
51
|
run_pd = true
|
52
52
|
else
|
53
|
-
run_number = determine_run_number(object, run_at)
|
53
|
+
run_number = determine_run_number(object, run_at)
|
54
54
|
run_pd = determine_run_pd(run_at, run_number)
|
55
55
|
end
|
56
56
|
run_pd
|
57
|
-
end
|
57
|
+
end
|
58
58
|
|
59
59
|
def determine_run_number(object, run_at)
|
60
60
|
if PutsDebuggerer.run_at? # check if global option is set
|
@@ -70,7 +70,7 @@ module PutsDebuggerer
|
|
70
70
|
else
|
71
71
|
PutsDebuggerer::RunDeterminer.increment_run_at_global_number
|
72
72
|
end
|
73
|
-
PutsDebuggerer::RunDeterminer.run_at_global_number
|
73
|
+
PutsDebuggerer::RunDeterminer.run_at_global_number
|
74
74
|
end
|
75
75
|
|
76
76
|
def determine_local_run_number(object, run_at)
|
@@ -89,11 +89,11 @@ module PutsDebuggerer
|
|
89
89
|
determine_run_pd_array(run_at, run_number)
|
90
90
|
elsif run_at.is_a?(Range)
|
91
91
|
determine_run_pd_range(run_at, run_number)
|
92
|
-
end
|
92
|
+
end
|
93
93
|
end
|
94
94
|
|
95
95
|
def determine_run_pd_integer(run_at, run_number)
|
96
|
-
run_pd = true if run_at == run_number
|
96
|
+
run_pd = true if run_at == run_number
|
97
97
|
end
|
98
98
|
|
99
99
|
def determine_run_pd_array(run_at, run_number)
|
@@ -1,16 +1,16 @@
|
|
1
1
|
module PutsDebuggerer
|
2
|
-
class SourceFile
|
2
|
+
class SourceFile
|
3
3
|
def initialize(file_path)
|
4
4
|
@file = File.new(file_path) if file_path
|
5
5
|
end
|
6
6
|
|
7
7
|
def source(source_line_count, source_line_number)
|
8
|
-
@source = ''
|
9
|
-
return @source if
|
8
|
+
@source = ''
|
9
|
+
return @source if RUBY_ENGINE == 'opal'
|
10
10
|
# For Opal Ruby compatibility, skip source lines if file does not respond to readline (as in Opal)
|
11
11
|
lines = source_lines(source_line_count, source_line_number)
|
12
12
|
@source = lines.join(' '*5) if @file.respond_to?(:readline)
|
13
|
-
@source
|
13
|
+
@source
|
14
14
|
end
|
15
15
|
|
16
16
|
def source_lines(source_line_count, source_line_number)
|
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: 0.11.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Maleh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-12-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: awesome_print
|