puts_debuggerer 0.11.0 → 0.13.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 43ff23befa76e5fc66ff64e550594c4e0c4a2055d586329ee731c075c6ab54a7
4
- data.tar.gz: 1224fadbcca6b036eac9ed58d9ce60d5e7f7a6cd3a6742de05e4f82cb9107b8e
3
+ metadata.gz: 6f1e480d2a8330d48a546c7e89a2479185cfad2bc1f6b8cf1a9750494de27406
4
+ data.tar.gz: e135390dd68993136fd2fd4d22d4721dd8a12454f5ce71f2ad164f453358e1db
5
5
  SHA512:
6
- metadata.gz: 13af30103a2bfa13e3e579f9083ed366fb4fa168e53a7c685e9181c60fb194dc24430e49d14348d4ae59f7573430b1f665987182b101a4a5da28394acf9b485e
7
- data.tar.gz: 3b6eb47ca8c5758f3ffe6405ca94031bc05ee2cfad09cbb1f20fec85aea0fef42c0900a9ccd43916f4f567aed1d7c8f5ec9ec779c69c586cd9f5052e8b809047
6
+ metadata.gz: 752b67073d6ffda81d890aa568a74f48f7f09b3321c4d5b6e7f51ea8a5c098b0feebe77e3ca5d4f0a80eb842844e8d76f8f75443ab075f153d761842594664db
7
+ data.tar.gz: bb327d1a2633282307da402569697746c4f0ba91e0c93955728fb9ba647bec9d7d2100406040afe950c630d4a0e9774d3afdc94ac0e8bf1795b429e231dda2d4
data/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.13.2
4
+
5
+ - Fix issue caused by MiniTest Rails having `IRB` constant declared despite being outside of IRB
6
+
7
+ ## 0.13.1
8
+
9
+ - Support `a: '[PD]'` shortcut to passing `announcer: '[PD]'`
10
+ - Support `c: :t` shortcut to passing `caller: true`
11
+
12
+ ## 0.13.0
13
+
14
+ - Support `h: :t` shortcut to passing `header: true`
15
+ - Support `f: :t` shortcut to passing `footer: true`
16
+ - Support `w: :t` shortcut to passing `wrapper: true`
17
+
18
+ ## 0.12.0
19
+
20
+ - Upgrade `awesome_print` to `~> 1.9.2`
21
+ - 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)` )
22
+ - Support empty use of pd statement + options (e.g. `pd` or `pd header: true`)
23
+
3
24
  ## 0.11.0
4
25
 
5
26
  - Pry support
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2017-2020 - Andy Maleh
1
+ Copyright (c) 2017-2021 - Andy Maleh
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -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
 
@@ -122,6 +122,14 @@ pd order_summary
122
122
  pd order_details
123
123
  ```
124
124
 
125
+ Or the `h` shortcut:
126
+
127
+ ```ruby
128
+ pd order_total, h: :t
129
+ pd order_summary
130
+ pd order_details
131
+ ```
132
+
125
133
  Output:
126
134
 
127
135
  ```
@@ -145,12 +153,20 @@ Output:
145
153
  => "[Hard Cover] Pragmatic Ruby Book - English Version"
146
154
  ```
147
155
 
148
- Wanna customize the header and add a footer too? No problem:
156
+ Wanna add a footer too? No problem!
149
157
 
150
158
  ```ruby
151
- pd order_total, header: '>'*80
159
+ pd order_total, header: true
152
160
  pd order_summary
153
- pd order_details, footer: '<'*80
161
+ pd order_details, footer: true
162
+ ```
163
+
164
+ Or use the `f` shortcut:
165
+
166
+ ```ruby
167
+ pd order_total, h: :t
168
+ pd order_summary
169
+ pd order_details, f: :t
154
170
  ```
155
171
 
156
172
  Output:
@@ -158,7 +174,7 @@ Output:
158
174
  ```
159
175
  (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)
160
176
  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]]
161
- >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
177
+ ################################################################################
162
178
  [PD] /Users/User/ordering/order.rb:39
163
179
  > pd order_total, header: '>'*80
164
180
  => 195.50
@@ -174,7 +190,7 @@ Output:
174
190
  [PD] /Users/User/ordering/order.rb:41
175
191
  > pd order_details, footer: '<'*80
176
192
  => "[Hard Cover] Pragmatic Ruby Book - English Version"
177
- <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
193
+ ################################################################################
178
194
  ```
179
195
 
180
196
  Need a quick stack trace? Just use the `caller` option (you may surround with header and footer too via `wrapper`).
@@ -185,6 +201,14 @@ pd order_summary
185
201
  pd order_details
186
202
  ```
187
203
 
204
+ Or use the `c` and `w` shortcuts:
205
+
206
+ ```ruby
207
+ pd order_total, c: :t, w: :t
208
+ pd order_summary
209
+ pd order_details
210
+ ```
211
+
188
212
  Output:
189
213
 
190
214
  ```
@@ -254,6 +278,14 @@ pd order_summary
254
278
  pd order_details
255
279
  ```
256
280
 
281
+ Or use shortcut syntax:
282
+
283
+ ```ruby
284
+ pd order_total, c: 3, w: :t
285
+ pd order_summary
286
+ pd order_details
287
+ ```
288
+
257
289
  ```
258
290
  (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)
259
291
  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]]
@@ -279,7 +311,7 @@ pd order_details
279
311
  => "[Hard Cover] Pragmatic Ruby Book - English Version"
280
312
  ```
281
313
 
282
- There are many more options and powerful features in [puts_debuggerer](https://rubygems.org/gems/puts_debuggerer) as detailed below.
314
+ There are many more options and features in [puts_debuggerer](https://rubygems.org/gems/puts_debuggerer) as detailed below.
283
315
 
284
316
  ## Instructions
285
317
 
@@ -288,7 +320,7 @@ There are many more options and powerful features in [puts_debuggerer](https://r
288
320
  Add the following to bundler's `Gemfile`.
289
321
 
290
322
  ```ruby
291
- gem 'puts_debuggerer', '~> 0.10.3'
323
+ gem 'puts_debuggerer', '~> 0.13.2'
292
324
  ```
293
325
 
294
326
  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.
@@ -298,7 +330,7 @@ This is the recommended way for [Rails](rubyonrails.org) apps. Optionally, you m
298
330
  Or manually install and require library.
299
331
 
300
332
  ```bash
301
- gem install puts_debuggerer -v0.10.3
333
+ gem install puts_debuggerer -v0.13.2
302
334
  ```
303
335
 
304
336
  ```ruby
@@ -311,7 +343,6 @@ Or the shorter form (often helpful to quickly troubleshoot an app):
311
343
  require 'pd'
312
344
  ```
313
345
 
314
-
315
346
  ### Awesome Print
316
347
 
317
348
  [puts_debuggerer](https://rubygems.org/gems/puts_debuggerer) comes with [awesome_print](https://github.com/awesome-print/awesome_print).
@@ -471,11 +502,11 @@ Example Printout:
471
502
  ```
472
503
 
473
504
  #### `PutsDebuggerer.header`
474
- (default = `'*'*80`)
505
+ (default = `'>'*80`) [shortcut: `h`]
475
506
 
476
507
  Header to include at the top of every print out.
477
508
  * Default value is `nil`
478
- * Value `true` enables header as `'*'*80`
509
+ * Value `true` enables header as `'>'*80`
479
510
  * Value `false`, `nil`, or empty string disables header
480
511
  * Any other string value gets set as a custom header
481
512
 
@@ -494,6 +525,21 @@ Prints out:
494
525
  => "1"
495
526
  ```
496
527
 
528
+ Shortcut Example:
529
+
530
+ ```ruby
531
+ pd (x=1), h: :t
532
+ ```
533
+
534
+ Prints out:
535
+
536
+ ```bash
537
+ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
538
+ [PD] /Users/User/example.rb:1
539
+ > pd (x=1), h: :t
540
+ => "1"
541
+ ```
542
+
497
543
  Global Option Example:
498
544
 
499
545
  ```ruby
@@ -516,11 +562,11 @@ Prints out:
516
562
  ```
517
563
 
518
564
  #### `PutsDebuggerer.footer`
519
- (default = `'*'*80`)
565
+ (default = `'<'*80`) [shortcut: `f`]
520
566
 
521
567
  Footer to include at the bottom of every print out.
522
568
  * Default value is `nil`
523
- * Value `true` enables footer as `'*'*80`
569
+ * Value `true` enables footer as `'<'*80`
524
570
  * Value `false`, `nil`, or empty string disables footer
525
571
  * Any other string value gets set as a custom footer
526
572
 
@@ -539,6 +585,21 @@ Prints out:
539
585
  <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
540
586
  ```
541
587
 
588
+ Shortcut Example:
589
+
590
+ ```ruby
591
+ pd (x=1), f: :t
592
+ ```
593
+
594
+ Prints out:
595
+
596
+ ```bash
597
+ [PD] /Users/User/example.rb:1
598
+ > pd (x=1), f: :t
599
+ => "1"
600
+ <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
601
+ ```
602
+
542
603
  Global Option Example:
543
604
 
544
605
  ```ruby
@@ -561,7 +622,7 @@ Prints out:
561
622
  ```
562
623
 
563
624
  #### `PutsDebuggerer.wrapper`
564
- (default = `'*'*80`)
625
+ (default = `'*'*80`) [shortcut: `w`]
565
626
 
566
627
  Wrapper to include at the top and bottom of every print out (both header and footer).
567
628
  * Default value is `nil`
@@ -585,6 +646,22 @@ Prints out:
585
646
  ********************************************************************************
586
647
  ```
587
648
 
649
+ Shortcut Example:
650
+
651
+ ```ruby
652
+ pd (x=1), w: :t
653
+ ```
654
+
655
+ Prints out:
656
+
657
+ ```bash
658
+ ********************************************************************************
659
+ [PD] /Users/User/example.rb:1
660
+ > pd x=1, w: :t
661
+ => "1"
662
+ ********************************************************************************
663
+ ```
664
+
588
665
  Global Option Example:
589
666
 
590
667
  ```ruby
@@ -717,7 +794,7 @@ Prints out:
717
794
  ```
718
795
 
719
796
  #### `PutsDebuggerer.announcer`
720
- (default = `"[PD]"`)
797
+ (default = `"[PD]"`) [shortcut: `a`]
721
798
 
722
799
  Announcer (e.g. `[PD]`) to announce every print out with (default: `"[PD]"`)
723
800
 
@@ -788,7 +865,7 @@ FOOTER: ************************************************************************
788
865
  ```
789
866
 
790
867
  #### `PutsDebuggerer.caller`
791
- (default = nil)
868
+ (default = nil) [shortcut: `c`]
792
869
 
793
870
  Caller backtrace included at the end of every print out
794
871
  Passed an argument of true/false, nil, or depth as an integer.
@@ -800,15 +877,33 @@ Example:
800
877
 
801
878
  ```ruby
802
879
  # File Name: /Users/User/sample_app/lib/sample.rb
803
- PutsDebuggerer.caller = 3
804
- pd (x=1)
880
+ pd (x=1), caller: 3
805
881
  ```
806
882
 
807
- Prints out:
883
+ Prints out (fictional):
808
884
 
809
885
  ```bash
810
- [PD] /Users/User/sample_app/lib/sample.rb:3
811
- > pd x=1
886
+ [PD] /Users/User/sample_app/lib/sample.rb:2
887
+ > pd x=1, caller: 3
888
+ => "1"
889
+ /Users/User/sample_app/lib/master_samples.rb:368:in \`block (3 levels) in <top (required)>\'
890
+ /Users/User/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/irb/workspace.rb:87:in \`eval\'
891
+ /Users/User/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/irb/workspace.rb:87:in \`evaluate\'
892
+ /Users/User/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/irb/context.rb:381:in \`evaluate\'
893
+ ```
894
+
895
+ Shortcut Example:
896
+
897
+ ```ruby
898
+ # File Name: /Users/User/sample_app/lib/sample.rb
899
+ pd (x=1), c: 3
900
+ ```
901
+
902
+ Prints out (fictional):
903
+
904
+ ```bash
905
+ [PD] /Users/User/sample_app/lib/sample.rb:2
906
+ > pd x=1, caller: 3
812
907
  => "1"
813
908
  /Users/User/sample_app/lib/master_samples.rb:368:in \`block (3 levels) in <top (required)>\'
814
909
  /Users/User/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/irb/workspace.rb:87:in \`eval\'
@@ -1009,4 +1104,4 @@ Note that it ignores the configured printer when printing exceptions as it relie
1009
1104
 
1010
1105
  [MIT](LICENSE.txt)
1011
1106
 
1012
- Copyright (c) 2017-2020 - Andy Maleh.
1107
+ Copyright (c) 2017-2021 - Andy Maleh.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.11.0
1
+ 0.13.2
@@ -147,7 +147,7 @@ module Kernel
147
147
  if defined?(Pry)
148
148
  @pry_instance ||= Pry.new
149
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)
150
+ elsif defined?(IRB) && TOPLEVEL_BINDING.receiver.respond_to?(:conf)
151
151
  source_line = TOPLEVEL_BINDING.receiver.conf.io.line(source_line_number) # TODO handle multi-lines in source_line_count
152
152
  else
153
153
  source_line = PutsDebuggerer::SourceFile.new(source_file).source(source_line_count, source_line_number)
@@ -1,7 +1,7 @@
1
1
  module PutsDebuggerer
2
2
  class SourceFile
3
3
  def initialize(file_path)
4
- @file = File.new(file_path) if file_path
4
+ @file = File.new(file_path) if file_path && File.exist?(file_path)
5
5
  end
6
6
 
7
7
  def source(source_line_count, source_line_number)
@@ -16,7 +16,7 @@ module PutsDebuggerer
16
16
  def source_lines(source_line_count, source_line_number)
17
17
  lines = []
18
18
  begin
19
- while @file.lineno < source_line_number + source_line_count
19
+ while @file && @file.lineno < source_line_number + source_line_count
20
20
  file_line_number = @file.lineno + 1
21
21
  file_line = @file.readline
22
22
  if file_line_number >= source_line_number && file_line_number < source_line_number + source_line_count
@@ -63,6 +63,14 @@ module PutsDebuggerer
63
63
  STACK_TRACE_CALL_LINE_NUMBER_REGEX = /\:(\d+)\:in /
64
64
  STACK_TRACE_CALL_SOURCE_FILE_REGEX = /[ ]*([^:]+)\:\d+\:in /
65
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
+ }
66
74
 
67
75
  class << self
68
76
  # Application root path to exclude when printing out file path
@@ -469,7 +477,18 @@ module PutsDebuggerer
469
477
  end
470
478
 
471
479
  def determine_options(objects)
472
- objects.delete_at(-1) if objects.size > 1 && objects.last.is_a?(Hash)
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]}]
473
492
  end
474
493
 
475
494
  def determine_object(objects)
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.11.0
4
+ version: 0.13.2
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-12-15 00:00:00.000000000 Z
11
+ date: 2021-12-21 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.31
224
210
  signing_key:
225
211
  specification_version: 4
226
212
  summary: Ruby library for improved puts debugging, automatically displaying bonus