puts_debuggerer 0.10.2 → 0.13.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c10b7cd1e10ee4448130b42cf869c55904445ec9038875c4da4339813ba7b6d6
4
- data.tar.gz: 973aaad4a4eda5bb9ef7add02f0b3a3b991bb84f6fd2ab461281c03aa5cc1404
3
+ metadata.gz: 8ebff6f84d78f7241fdb021e55a6d90ab94a1a2827cfd9a1dee2280a28a34d42
4
+ data.tar.gz: d5960273c6cde51e258c4b426cfff5ff00bf67f4961c32c85011698888c228d2
5
5
  SHA512:
6
- metadata.gz: 9b029b0cfeb9b219313e80b72c8be7094db40101a51bc6b430254110c4e2b662eaed5706831372909f950fa1f7503a20544553491d29f275f004ab26be2c1419
7
- data.tar.gz: cdd0aaa7734d5b98a1efba63fdc8aebd514ad76a694a1362b066728ffb0605005f8093d83355aa7c10d32a26eedf2e372042a62ecfdc0e04271fa2e24899ddb1
6
+ metadata.gz: 9b82d39c624a8d151d6d72c73b0f464e74935cf4d0c88140c700f533647ad3f089b8be41cb3f0e2e7c97ea06b917d57ef4f91292accc6a2b74d4cd50198ca442
7
+ data.tar.gz: ffcc096603c4b46a1e134b2ab8de5090403fc579505bd6a7a5b9eaa9e87561faa6ef5d5196d88157fe92ea370a4c309bc0edeb9da278ec8128cdbf88743884c5
data/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.13.0
4
+
5
+ - Support `h: :t` shortcut to passing `header: true`
6
+ - Support `f: :t` shortcut to passing `footer: true`
7
+ - Support `w: :t` shortcut to passing `wrapper: true`
8
+
9
+ ## 0.12.0
10
+
11
+ - Upgrade `awesome_print` to `~> 1.9.2`
12
+ - Support passing pd options as part of a printed hash instead of requiring a separate hash (e.g. `pd(path: path, header: true)` instead of `pd({path: path}, header: true)` )
13
+ - Support empty use of pd statement + options (e.g. `pd` or `pd header: true`)
14
+
15
+ ## 0.11.0
16
+
17
+ - Pry support
18
+ - In Opal, print exceptions as errors in the web console using an alternative to full_message since it's not implemented in Opal yet
19
+ - Fix `pd_inspect` and `pdi` in IRB
20
+
3
21
  ## 0.10.2
4
22
 
5
23
  - 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
 
@@ -33,7 +33,7 @@ Output:
33
33
 
34
34
  ## Background
35
35
 
36
- 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.
36
+ 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.
37
37
 
38
38
  puts_debuggerer automates that work via the short and simple `pd` command, automatically printing meaningful headers for output and accelerating problem solving work due to ease of typing.
39
39
 
@@ -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 (or `h`):
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,18 +166,18 @@ 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
  ```
193
179
 
194
- Need a quick stack trace? Just use the `caller` option (you may surround with header and footer too via `wrapper`).
180
+ Need a quick stack trace? Just use the `caller` option (you may surround with header and footer too via `wrapper` or `w`).
195
181
 
196
182
  ```ruby
197
183
  pd order_total, caller: true, wrapper: true
@@ -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,17 +269,17 @@ 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
 
296
- There are many more options and powerful features in [puts_debuggerer](https://rubygems.org/gems/puts_debuggerer) as detailed below.
282
+ There are many more options and features in [puts_debuggerer](https://rubygems.org/gems/puts_debuggerer) as detailed below.
297
283
 
298
284
  ## Instructions
299
285
 
@@ -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.2'
291
+ gem 'puts_debuggerer', '~> 0.13.1'
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.2
301
+ gem install puts_debuggerer -v0.13.1
316
302
  ```
317
303
 
318
304
  ```ruby
@@ -325,7 +311,6 @@ Or the shorter form (often helpful to quickly troubleshoot an app):
325
311
  require 'pd'
326
312
  ```
327
313
 
328
-
329
314
  ### Awesome Print
330
315
 
331
316
  [puts_debuggerer](https://rubygems.org/gems/puts_debuggerer) comes with [awesome_print](https://github.com/awesome-print/awesome_print).
@@ -371,7 +356,7 @@ Output:
371
356
  => "Show me the result of the calculation: 4.0"
372
357
  ```
373
358
 
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).
359
+ 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
360
 
376
361
  Second, quickly locate printed lines using the Find feature (e.g. CTRL+F) by looking for:
377
362
  * [PD]
@@ -405,14 +390,14 @@ Happy puts_debuggerering!
405
390
  You may want to just return the string produced by the `pd` method without printing it.
406
391
 
407
392
  In that case, you may use the `pd` alternative to `object.inspect`:
408
- - `object.pd_inspect`
393
+ - `object.pd_inspect`
409
394
  - `obj.pdi` (shorter alias)
410
395
 
411
396
  This returns the `pd` formatted string without printing to the terminal or log files.
412
397
 
413
- #### Ruby Logger and Logging::Logger
398
+ #### Ruby Logger and Logging::Logger
414
399
 
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)).
400
+ 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
401
 
417
402
  ### Options
418
403
 
@@ -436,7 +421,7 @@ pd data, header: true
436
421
  Prints out:
437
422
 
438
423
  ```bash
439
- ********************************************************************************
424
+ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
440
425
  [PD] /Users/User/project/piecemeal.rb:3
441
426
  > pd data, header: true
442
427
  => [1, [2, 3]]
@@ -485,11 +470,11 @@ Example Printout:
485
470
  ```
486
471
 
487
472
  #### `PutsDebuggerer.header`
488
- (default = `'*'*80`)
473
+ (default = `'>'*80`)
489
474
 
490
475
  Header to include at the top of every print out.
491
476
  * Default value is `nil`
492
- * Value `true` enables header as `'*'*80`
477
+ * Value `true` enables header as `'>'*80`
493
478
  * Value `false`, `nil`, or empty string disables header
494
479
  * Any other string value gets set as a custom header
495
480
 
@@ -502,12 +487,27 @@ pd (x=1), header: true
502
487
  Prints out:
503
488
 
504
489
  ```bash
505
- ********************************************************************************
490
+ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
506
491
  [PD] /Users/User/example.rb:1
507
492
  > pd (x=1), header: true
508
493
  => "1"
509
494
  ```
510
495
 
496
+ Shortcut Example:
497
+
498
+ ```ruby
499
+ pd (x=1), h: :t
500
+ ```
501
+
502
+ Prints out:
503
+
504
+ ```bash
505
+ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
506
+ [PD] /Users/User/example.rb:1
507
+ > pd (x=1), h: :t
508
+ => "1"
509
+ ```
510
+
511
511
  Global Option Example:
512
512
 
513
513
  ```ruby
@@ -519,22 +519,22 @@ pd (x=2)
519
519
  Prints out:
520
520
 
521
521
  ```bash
522
- ********************************************************************************
522
+ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
523
523
  [PD] /Users/User/example.rb:2
524
524
  > pd (x=1)
525
525
  => "1"
526
- ********************************************************************************
526
+ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
527
527
  [PD] /Users/User/example.rb:3
528
528
  > pd (x=2)
529
529
  => "2"
530
530
  ```
531
531
 
532
532
  #### `PutsDebuggerer.footer`
533
- (default = `'*'*80`)
533
+ (default = `'<'*80`)
534
534
 
535
535
  Footer to include at the bottom of every print out.
536
536
  * Default value is `nil`
537
- * Value `true` enables footer as `'*'*80`
537
+ * Value `true` enables footer as `'<'*80`
538
538
  * Value `false`, `nil`, or empty string disables footer
539
539
  * Any other string value gets set as a custom footer
540
540
 
@@ -550,7 +550,22 @@ Prints out:
550
550
  [PD] /Users/User/example.rb:1
551
551
  > pd (x=1), footer: true
552
552
  => "1"
553
- ********************************************************************************
553
+ <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
554
+ ```
555
+
556
+ Shortcut Example:
557
+
558
+ ```ruby
559
+ pd (x=1), f: :t
560
+ ```
561
+
562
+ Prints out:
563
+
564
+ ```bash
565
+ [PD] /Users/User/example.rb:1
566
+ > pd (x=1), f: :t
567
+ => "1"
568
+ <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
554
569
  ```
555
570
 
556
571
  Global Option Example:
@@ -567,11 +582,11 @@ Prints out:
567
582
  [PD] /Users/User/example.rb:2
568
583
  > pd (x=1)
569
584
  => "1"
570
- ********************************************************************************
585
+ <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
571
586
  [PD] /Users/User/example.rb:3
572
587
  > pd (x=2)
573
588
  => "2"
574
- ********************************************************************************
589
+ <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
575
590
  ```
576
591
 
577
592
  #### `PutsDebuggerer.wrapper`
@@ -599,6 +614,22 @@ Prints out:
599
614
  ********************************************************************************
600
615
  ```
601
616
 
617
+ Shortcut Example:
618
+
619
+ ```ruby
620
+ pd (x=1), w: :t
621
+ ```
622
+
623
+ Prints out:
624
+
625
+ ```bash
626
+ ********************************************************************************
627
+ [PD] /Users/User/example.rb:1
628
+ > pd x=1, w: :t
629
+ => "1"
630
+ ********************************************************************************
631
+ ```
632
+
602
633
  Global Option Example:
603
634
 
604
635
  ```ruby
@@ -625,7 +656,7 @@ Prints out:
625
656
  #### `PutsDebuggerer.source_line_count`
626
657
  (default = `1`)
627
658
 
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.
659
+ 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
660
 
630
661
  Example:
631
662
 
@@ -669,7 +700,7 @@ Examples of a global method are `:puts` and `:print`.
669
700
  An example of a lambda expression is `lambda {|output| Rails.logger.info(output)}`
670
701
  Examples of a logger are a Ruby `Logger` instance or `Logging::Logger` instance
671
702
 
672
- When a logger is supplied, it is automatically enhanced with a PutsDebuggerer formatter to use
703
+ When a logger is supplied, it is automatically enhanced with a PutsDebuggerer formatter to use
673
704
  when calling logger methods outside of PutsDebuggerer (e.g. `logger.error('msg')` will use `pd`)
674
705
 
675
706
  Printer may be set to `false` to avoid printing and only return the formatted string.
@@ -975,11 +1006,11 @@ Prints out `puts __caller_source_line__`
975
1006
 
976
1007
  ## Compatibility
977
1008
 
978
- [puts_debuggerer](https://rubygems.org/gems/puts_debuggerer) is fully compatible with:
1009
+ [puts_debuggerer](https://rubygems.org/gems/puts_debuggerer) is fully compatible with:
979
1010
  - [Ruby](https://www.ruby-lang.org/en/)
980
1011
  - [JRuby](https://www.jruby.org/)
981
- - IRB
982
- - Rails Console.
1012
+ - IRB (including Rails Console)
1013
+ - Pry
983
1014
 
984
1015
  ### Opal Ruby
985
1016
 
@@ -993,10 +1024,12 @@ Here is an example of `pd` output in Opal:
993
1024
 
994
1025
  ```
995
1026
  [PD] http://localhost:3000/assets/views/garderie_rainbow_daily_agenda/app_view.self-72626d75e0f68a619b1c8ad139535d799d45ab6c730d083820b790d71338e983.js?body=1:72:12
996
- >
1027
+ >
997
1028
  => "body"
998
1029
  ```
999
1030
 
1031
+ 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.
1032
+
1000
1033
  ## Change Log
1001
1034
 
1002
1035
  [CHANGELOG.md](CHANGELOG.md)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.10.2
1
+ 0.13.1
@@ -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 = '*'*80
9
+ HEADER_DEFAULT = '>'*80
10
10
  WRAPPER_DEFAULT = '*'*80
11
- FOOTER_DEFAULT = '*'*80
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) && object.respond_to?(:full_message)
31
- puts object.full_message
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
@@ -59,6 +63,14 @@ module PutsDebuggerer
59
63
  STACK_TRACE_CALL_LINE_NUMBER_REGEX = /\:(\d+)\:in /
60
64
  STACK_TRACE_CALL_SOURCE_FILE_REGEX = /[ ]*([^:]+)\:\d+\:in /
61
65
  STACK_TRACE_CALL_SOURCE_FILE_REGEX_OPAL = /(http[^\)]+)/
66
+ OPTIONS = [:app_path, :source_line_count, :header, :h, :wrapper, :w, :footer, :f, :printer, :print_engine, :announcer, :formatter, :caller, :run_at]
67
+ OPTION_ALIASES = {
68
+ a: :announcer,
69
+ c: :caller,
70
+ h: :header,
71
+ f: :footer,
72
+ w: :wrapper,
73
+ }
62
74
 
63
75
  class << self
64
76
  # Application root path to exclude when printing out file path
@@ -167,7 +179,7 @@ module PutsDebuggerer
167
179
  instance_variable_set(:"@#{boundary_option}", nil)
168
180
  else
169
181
  instance_variable_set(:"@#{boundary_option}", value)
170
- end
182
+ end
171
183
  end
172
184
 
173
185
  define_method("#{boundary_option}?") do
@@ -220,10 +232,10 @@ module PutsDebuggerer
220
232
  end
221
233
 
222
234
  def printer_default
223
- Object.const_defined?(:Rails) ? PRINTER_RAILS : PRINTER_DEFAULT
235
+ Object.const_defined?(:Rails) ? PRINTER_RAILS : PRINTER_DEFAULT
224
236
  end
225
237
 
226
- # Logger original formatter before it was decorated with PutsDebuggerer::LOGGER_FORMATTER_DECORATOR
238
+ # Logger original formatter before it was decorated with PutsDebuggerer::LOGGER_FORMATTER_DECORATOR
227
239
  # upon setting the logger as a printer.
228
240
  attr_reader :logger_original_formatter
229
241
 
@@ -256,8 +268,8 @@ module PutsDebuggerer
256
268
  # ]
257
269
  def print_engine
258
270
  if @print_engine.nil?
259
- require 'awesome_print' if RUBY_PLATFORM != 'opal'
260
- @print_engine = print_engine_default
271
+ require 'awesome_print' if RUBY_ENGINE != 'opal'
272
+ @print_engine = print_engine_default
261
273
  end
262
274
  @print_engine
263
275
  end
@@ -271,7 +283,7 @@ module PutsDebuggerer
271
283
  end
272
284
 
273
285
  def print_engine_default
274
- Object.const_defined?(:AwesomePrint) ? PRINT_ENGINE_DEFAULT : :p
286
+ Object.const_defined?(:AwesomePrint) ? PRINT_ENGINE_DEFAULT : :p
275
287
  end
276
288
 
277
289
  # Announcer (e.g. [PD]) to announce every print out with (default: "[PD]")
@@ -464,8 +476,19 @@ module PutsDebuggerer
464
476
  !!@run_at
465
477
  end
466
478
 
467
- def determine_options(objects)
468
- objects.delete_at(-1) if objects.size > 1 && objects.last.is_a?(Hash)
479
+ def determine_options(objects)
480
+ if objects.size > 1 && objects.last.is_a?(Hash)
481
+ convert_options(objects.delete_at(-1))
482
+ elsif objects.size == 1 && objects.first.is_a?(Hash)
483
+ hash = objects.first
484
+ convert_options(hash.slice(*OPTIONS).tap do
485
+ hash.delete_if {|option| OPTIONS.include?(option)}
486
+ end)
487
+ end
488
+ end
489
+
490
+ def convert_options(hash)
491
+ Hash[hash.map { |key, value| OPTION_ALIASES[key] ? ( value == :t ? [OPTION_ALIASES[key], true] : [OPTION_ALIASES[key], value] ) : [key, value]}]
469
492
  end
470
493
 
471
494
  def determine_object(objects)
@@ -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 PutsDebuggerer.printer.is_a?(Proc)
53
- PutsDebuggerer.printer.call(string)
54
- elsif PutsDebuggerer.printer.is_a?(Logger)
55
- logger_formatter = PutsDebuggerer.printer.formatter
56
- begin
57
- PutsDebuggerer.printer.formatter = PutsDebuggerer.logger_original_formatter
58
- PutsDebuggerer.printer.debug(string)
59
- ensure
60
- PutsDebuggerer.printer.formatter = logger_formatter
61
- end
62
- elsif PutsDebuggerer.printer.is_a?(Logging::Logger)
63
- logging_layouts = PutsDebuggerer.printer.appenders.reduce({}) do |hash, appender|
64
- hash.merge(appender => appender.layout)
65
- end
66
- begin
67
- PutsDebuggerer.logging_original_layouts.each do |appender, original_layout|
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
- PutsDebuggerer.printer.debug(string)
71
- ensure
72
- PutsDebuggerer.logging_original_layouts.each do |appender, original_layout|
73
- appender.layout = logging_layouts[appender]
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
- end
76
- elsif PutsDebuggerer.printer != false
77
- send(PutsDebuggerer.send(:printer), string)
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 RUBY_PLATFORM == 'opal'
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 RUBY_PLATFORM == 'opal'
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 = RUBY_PLATFORM == 'opal' ? PutsDebuggerer::STACK_TRACE_CALL_SOURCE_FILE_REGEX_OPAL : PutsDebuggerer::STACK_TRACE_CALL_SOURCE_FILE_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 source_file == '(irb)'
144
- source_line = conf.io.line(source_line_number) # TODO handle multi-lines in source_line_count
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 = RUBY_PLATFORM == 'opal' ? PutsDebuggerer::CALLER_DEPTH_ZERO_OPAL : PutsDebuggerer::CALLER_DEPTH_ZERO
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 RUBY_PLATFORM == 'opal'
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.10.2
4
+ version: 0.13.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: 2020-10-02 00:00:00.000000000 Z
11
+ date: 2021-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: awesome_print
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.8.0
19
+ version: 1.9.2
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.8.0
26
+ version: 1.9.2
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -84,14 +84,14 @@ dependencies:
84
84
  name: bundler
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - "~>"
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
89
  version: 2.1.4
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - "~>"
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: 2.1.4
97
97
  - !ruby/object:Gem::Dependency
@@ -136,20 +136,6 @@ dependencies:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
138
  version: 0.7.0
139
- - !ruby/object:Gem::Dependency
140
- name: undercover
141
- requirement: !ruby/object:Gem::Requirement
142
- requirements:
143
- - - "~>"
144
- - !ruby/object:Gem::Version
145
- version: 0.3.4
146
- type: :development
147
- prerelease: false
148
- version_requirements: !ruby/object:Gem::Requirement
149
- requirements:
150
- - - "~>"
151
- - !ruby/object:Gem::Version
152
- version: 0.3.4
153
139
  - !ruby/object:Gem::Dependency
154
140
  name: logging
155
141
  requirement: !ruby/object:Gem::Requirement
@@ -220,7 +206,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
220
206
  - !ruby/object:Gem::Version
221
207
  version: '0'
222
208
  requirements: []
223
- rubygems_version: 3.1.4
209
+ rubygems_version: 3.2.3
224
210
  signing_key:
225
211
  specification_version: 4
226
212
  summary: Ruby library for improved puts debugging, automatically displaying bonus