puts_debuggerer 0.12.0 → 0.13.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 85cc76378a88f1e7c8019f347e69070190ca4f051619fc60dee05d2ff3e83dda
4
- data.tar.gz: fb66e2375aa5624c8910d429032e9d99367b1ed5560aa7e364bd431167f5a291
3
+ metadata.gz: 0b3e07943392edd34351e36147a4582452c9af5b8ca592c815d9be8b43578384
4
+ data.tar.gz: a97d234a8d2b8f7c995066911244628b3b1e0e6feb7ae07846551f884074cb23
5
5
  SHA512:
6
- metadata.gz: e61dc7234af7e6392bc61a8510a63846c65a6cf305e5ba2dd2ce807d6ec72d259675cf0f32bddb45709d0d823e2123d8e3ce4ecce14c8165bb15874354128c24
7
- data.tar.gz: 5140b36a4d575b4f27e19929c70437d8e30a45d5085b682106868c2e915e49be6744a6aea772946b8e05b3ec2d1ed4d3be21ba163dec2db56a21eeaa6b991650
6
+ metadata.gz: 7ffdfe67fbe6b650594023cafb7998553bd0212268b833df16061fa3b2ca7dc9e92d3a406a0b04eb28dcd903128271ec8ab62cf54f55db5f32cc689bfb25197d
7
+ data.tar.gz: 17b022318d9e0d7044b24e5c5c9602549784237df32ec75c7c01b393ace9eece7389b071832f823e881da7925aa32262ba57e1b8d348220747e6d17ea0ba4909
data/CHANGELOG.md CHANGED
@@ -1,8 +1,28 @@
1
1
  # Change Log
2
2
 
3
+ ## 0.13.3
4
+
5
+ - Update default `printer` behavior for Rails to always output via `puts` (not just in tests) in addition to `Rails.logger.debug`
6
+ - Update custom implementation of `caller` for Opal to accept args (optional `start` and `length` or alternatively `range`) just like the Ruby API
7
+
8
+ ## 0.13.2
9
+
10
+ - Fix issue caused by MiniTest Rails having `IRB` constant declared despite being outside of IRB
11
+
12
+ ## 0.13.1
13
+
14
+ - Support `a: '[PD]'` shortcut to passing `announcer: '[PD]'`
15
+ - Support `c: :t` shortcut to passing `caller: true`
16
+
17
+ ## 0.13.0
18
+
19
+ - Support `h: :t` shortcut to passing `header: true`
20
+ - Support `f: :t` shortcut to passing `footer: true`
21
+ - Support `w: :t` shortcut to passing `wrapper: true`
22
+
3
23
  ## 0.12.0
4
24
 
5
- - Upgrade `awesome_print` to `~> 0.9.2`
25
+ - Upgrade `awesome_print` to `~> 1.9.2`
6
26
  - 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)` )
7
27
  - Support empty use of pd statement + options (e.g. `pd` or `pd header: true`)
8
28
 
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
@@ -1,4 +1,5 @@
1
1
  # Puts Debuggerer (debugger-less debugging FTW)
2
+ ## [State of the Art Rails 2021](https://github.com/DanielVartanov/state-of-the-art-rails)
2
3
  [![Gem Version](https://badge.fury.io/rb/puts_debuggerer.svg)](http://badge.fury.io/rb/puts_debuggerer)
3
4
  [![Build Status](https://travis-ci.org/AndyObtiva/puts_debuggerer.svg?branch=master)](https://travis-ci.org/AndyObtiva/puts_debuggerer)
4
5
  [![Coverage Status](https://coveralls.io/repos/github/AndyObtiva/puts_debuggerer/badge.svg?branch=master)](https://coveralls.io/github/AndyObtiva/puts_debuggerer?branch=master)
@@ -122,6 +123,14 @@ pd order_summary
122
123
  pd order_details
123
124
  ```
124
125
 
126
+ Or the `h` shortcut:
127
+
128
+ ```ruby
129
+ pd order_total, h: :t
130
+ pd order_summary
131
+ pd order_details
132
+ ```
133
+
125
134
  Output:
126
135
 
127
136
  ```
@@ -145,12 +154,20 @@ Output:
145
154
  => "[Hard Cover] Pragmatic Ruby Book - English Version"
146
155
  ```
147
156
 
148
- Wanna customize the header and add a footer too? No problem:
157
+ Wanna add a footer too? No problem!
149
158
 
150
159
  ```ruby
151
- pd order_total, header: '>'*80
160
+ pd order_total, header: true
152
161
  pd order_summary
153
- pd order_details, footer: '<'*80
162
+ pd order_details, footer: true
163
+ ```
164
+
165
+ Or use the `f` shortcut:
166
+
167
+ ```ruby
168
+ pd order_total, h: :t
169
+ pd order_summary
170
+ pd order_details, f: :t
154
171
  ```
155
172
 
156
173
  Output:
@@ -158,7 +175,7 @@ Output:
158
175
  ```
159
176
  (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
177
  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
- >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
178
+ ################################################################################
162
179
  [PD] /Users/User/ordering/order.rb:39
163
180
  > pd order_total, header: '>'*80
164
181
  => 195.50
@@ -174,7 +191,7 @@ Output:
174
191
  [PD] /Users/User/ordering/order.rb:41
175
192
  > pd order_details, footer: '<'*80
176
193
  => "[Hard Cover] Pragmatic Ruby Book - English Version"
177
- <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
194
+ ################################################################################
178
195
  ```
179
196
 
180
197
  Need a quick stack trace? Just use the `caller` option (you may surround with header and footer too via `wrapper`).
@@ -185,6 +202,14 @@ pd order_summary
185
202
  pd order_details
186
203
  ```
187
204
 
205
+ Or use the `c` and `w` shortcuts:
206
+
207
+ ```ruby
208
+ pd order_total, c: :t, w: :t
209
+ pd order_summary
210
+ pd order_details
211
+ ```
212
+
188
213
  Output:
189
214
 
190
215
  ```
@@ -254,6 +279,14 @@ pd order_summary
254
279
  pd order_details
255
280
  ```
256
281
 
282
+ Or use shortcut syntax:
283
+
284
+ ```ruby
285
+ pd order_total, c: 3, w: :t
286
+ pd order_summary
287
+ pd order_details
288
+ ```
289
+
257
290
  ```
258
291
  (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
292
  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 +312,7 @@ pd order_details
279
312
  => "[Hard Cover] Pragmatic Ruby Book - English Version"
280
313
  ```
281
314
 
282
- There are many more options and powerful features in [puts_debuggerer](https://rubygems.org/gems/puts_debuggerer) as detailed below.
315
+ There are many more options and features in [puts_debuggerer](https://rubygems.org/gems/puts_debuggerer) as detailed below.
283
316
 
284
317
  ## Instructions
285
318
 
@@ -288,7 +321,7 @@ There are many more options and powerful features in [puts_debuggerer](https://r
288
321
  Add the following to bundler's `Gemfile`.
289
322
 
290
323
  ```ruby
291
- gem 'puts_debuggerer', '~> 0.12.0'
324
+ gem 'puts_debuggerer', '~> 0.13.3'
292
325
  ```
293
326
 
294
327
  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 +331,7 @@ This is the recommended way for [Rails](rubyonrails.org) apps. Optionally, you m
298
331
  Or manually install and require library.
299
332
 
300
333
  ```bash
301
- gem install puts_debuggerer -v0.12.0
334
+ gem install puts_debuggerer -v0.13.3
302
335
  ```
303
336
 
304
337
  ```ruby
@@ -470,7 +503,7 @@ Example Printout:
470
503
  ```
471
504
 
472
505
  #### `PutsDebuggerer.header`
473
- (default = `'>'*80`)
506
+ (default = `'>'*80`) [shortcut: `h`]
474
507
 
475
508
  Header to include at the top of every print out.
476
509
  * Default value is `nil`
@@ -493,6 +526,21 @@ Prints out:
493
526
  => "1"
494
527
  ```
495
528
 
529
+ Shortcut Example:
530
+
531
+ ```ruby
532
+ pd (x=1), h: :t
533
+ ```
534
+
535
+ Prints out:
536
+
537
+ ```bash
538
+ >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
539
+ [PD] /Users/User/example.rb:1
540
+ > pd (x=1), h: :t
541
+ => "1"
542
+ ```
543
+
496
544
  Global Option Example:
497
545
 
498
546
  ```ruby
@@ -515,7 +563,7 @@ Prints out:
515
563
  ```
516
564
 
517
565
  #### `PutsDebuggerer.footer`
518
- (default = `'<'*80`)
566
+ (default = `'<'*80`) [shortcut: `f`]
519
567
 
520
568
  Footer to include at the bottom of every print out.
521
569
  * Default value is `nil`
@@ -538,6 +586,21 @@ Prints out:
538
586
  <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
539
587
  ```
540
588
 
589
+ Shortcut Example:
590
+
591
+ ```ruby
592
+ pd (x=1), f: :t
593
+ ```
594
+
595
+ Prints out:
596
+
597
+ ```bash
598
+ [PD] /Users/User/example.rb:1
599
+ > pd (x=1), f: :t
600
+ => "1"
601
+ <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
602
+ ```
603
+
541
604
  Global Option Example:
542
605
 
543
606
  ```ruby
@@ -560,7 +623,7 @@ Prints out:
560
623
  ```
561
624
 
562
625
  #### `PutsDebuggerer.wrapper`
563
- (default = `'*'*80`)
626
+ (default = `'*'*80`) [shortcut: `w`]
564
627
 
565
628
  Wrapper to include at the top and bottom of every print out (both header and footer).
566
629
  * Default value is `nil`
@@ -584,6 +647,22 @@ Prints out:
584
647
  ********************************************************************************
585
648
  ```
586
649
 
650
+ Shortcut Example:
651
+
652
+ ```ruby
653
+ pd (x=1), w: :t
654
+ ```
655
+
656
+ Prints out:
657
+
658
+ ```bash
659
+ ********************************************************************************
660
+ [PD] /Users/User/example.rb:1
661
+ > pd x=1, w: :t
662
+ => "1"
663
+ ********************************************************************************
664
+ ```
665
+
587
666
  Global Option Example:
588
667
 
589
668
  ```ruby
@@ -716,7 +795,7 @@ Prints out:
716
795
  ```
717
796
 
718
797
  #### `PutsDebuggerer.announcer`
719
- (default = `"[PD]"`)
798
+ (default = `"[PD]"`) [shortcut: `a`]
720
799
 
721
800
  Announcer (e.g. `[PD]`) to announce every print out with (default: `"[PD]"`)
722
801
 
@@ -787,7 +866,7 @@ FOOTER: ************************************************************************
787
866
  ```
788
867
 
789
868
  #### `PutsDebuggerer.caller`
790
- (default = nil)
869
+ (default = nil) [shortcut: `c`]
791
870
 
792
871
  Caller backtrace included at the end of every print out
793
872
  Passed an argument of true/false, nil, or depth as an integer.
@@ -799,15 +878,33 @@ Example:
799
878
 
800
879
  ```ruby
801
880
  # File Name: /Users/User/sample_app/lib/sample.rb
802
- PutsDebuggerer.caller = 3
803
- pd (x=1)
881
+ pd (x=1), caller: 3
804
882
  ```
805
883
 
806
- Prints out:
884
+ Prints out (fictional):
807
885
 
808
886
  ```bash
809
- [PD] /Users/User/sample_app/lib/sample.rb:3
810
- > pd x=1
887
+ [PD] /Users/User/sample_app/lib/sample.rb:2
888
+ > pd x=1, caller: 3
889
+ => "1"
890
+ /Users/User/sample_app/lib/master_samples.rb:368:in \`block (3 levels) in <top (required)>\'
891
+ /Users/User/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/irb/workspace.rb:87:in \`eval\'
892
+ /Users/User/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/irb/workspace.rb:87:in \`evaluate\'
893
+ /Users/User/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/irb/context.rb:381:in \`evaluate\'
894
+ ```
895
+
896
+ Shortcut Example:
897
+
898
+ ```ruby
899
+ # File Name: /Users/User/sample_app/lib/sample.rb
900
+ pd (x=1), c: 3
901
+ ```
902
+
903
+ Prints out (fictional):
904
+
905
+ ```bash
906
+ [PD] /Users/User/sample_app/lib/sample.rb:2
907
+ > pd x=1, caller: 3
811
908
  => "1"
812
909
  /Users/User/sample_app/lib/master_samples.rb:368:in \`block (3 levels) in <top (required)>\'
813
910
  /Users/User/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/irb/workspace.rb:87:in \`eval\'
@@ -1008,4 +1105,4 @@ Note that it ignores the configured printer when printing exceptions as it relie
1008
1105
 
1009
1106
  [MIT](LICENSE.txt)
1010
1107
 
1011
- Copyright (c) 2017-2020 - Andy Maleh.
1108
+ Copyright (c) 2017-2021 - Andy Maleh.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.12.0
1
+ 0.13.3
@@ -88,11 +88,23 @@ module Kernel
88
88
 
89
89
  # Implement caller backtrace method in Opal since it returns an empty array in Opal v1
90
90
  if RUBY_ENGINE == 'opal'
91
- def caller
91
+ def caller(*args)
92
+ dup_args = args.dup
93
+ start = args.shift if args.first.is_a?(Integer)
94
+ length = args.shift if args.first.is_a?(Integer)
95
+ range = args.shift if args.first.is_a?(Range)
96
+ if range
97
+ start = range.begin
98
+ length = range.end - start
99
+ end
92
100
  begin
93
101
  raise 'error'
94
102
  rescue => e
95
- e.backtrace[2..-1]
103
+ the_backtrace = e.backtrace
104
+ start ||= 0
105
+ start = 2 + start
106
+ length ||= the_backtrace.size - start
107
+ the_backtrace[start, length]
96
108
  end
97
109
  end
98
110
  end
@@ -147,7 +159,7 @@ module Kernel
147
159
  if defined?(Pry)
148
160
  @pry_instance ||= Pry.new
149
161
  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)
162
+ elsif defined?(IRB) && TOPLEVEL_BINDING.receiver.respond_to?(:conf)
151
163
  source_line = TOPLEVEL_BINDING.receiver.conf.io.line(source_line_number) # TODO handle multi-lines in source_line_count
152
164
  else
153
165
  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
@@ -42,7 +42,7 @@ module PutsDebuggerer
42
42
  end
43
43
  PRINTER_DEFAULT = :puts
44
44
  PRINTER_RAILS = lambda do |output|
45
- puts output if Rails.env.test?
45
+ puts output
46
46
  Rails.logger.debug(output)
47
47
  end
48
48
  PRINT_ENGINE_DEFAULT = :ap
@@ -63,7 +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, :wrapper, :footer, :printer, :print_engine, :announcer, :formatter, :caller, :run_at]
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
+ }
67
74
 
68
75
  class << self
69
76
  # Application root path to exclude when printing out file path
@@ -471,14 +478,18 @@ module PutsDebuggerer
471
478
 
472
479
  def determine_options(objects)
473
480
  if objects.size > 1 && objects.last.is_a?(Hash)
474
- objects.delete_at(-1)
481
+ convert_options(objects.delete_at(-1))
475
482
  elsif objects.size == 1 && objects.first.is_a?(Hash)
476
483
  hash = objects.first
477
- hash.slice(*OPTIONS).tap do
484
+ convert_options(hash.slice(*OPTIONS).tap do
478
485
  hash.delete_if {|option| OPTIONS.include?(option)}
479
- end
486
+ end)
480
487
  end
481
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]}]
492
+ end
482
493
 
483
494
  def determine_object(objects)
484
495
  objects.compact.size > 1 ? objects : objects.first
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.12.0
4
+ version: 0.13.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Maleh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-15 00:00:00.000000000 Z
11
+ date: 2022-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: awesome_print
@@ -30,28 +30,28 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 3.5.0
33
+ version: '3.5'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 3.5.0
40
+ version: '3.5'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec-mocks
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 3.5.0
47
+ version: '3.5'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 3.5.0
54
+ version: '3.5'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rdoc
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -206,7 +206,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
206
206
  - !ruby/object:Gem::Version
207
207
  version: '0'
208
208
  requirements: []
209
- rubygems_version: 3.2.3
209
+ rubygems_version: 3.3.1
210
210
  signing_key:
211
211
  specification_version: 4
212
212
  summary: Ruby library for improved puts debugging, automatically displaying bonus