puts_debuggerer 0.13.0 → 0.13.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +18 -0
- data/LICENSE.txt +1 -1
- data/README.md +96 -28
- data/VERSION +1 -1
- data/lib/puts_debuggerer/core_ext/kernel.rb +15 -3
- data/lib/puts_debuggerer/source_file.rb +2 -2
- data/lib/puts_debuggerer.rb +3 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5342d5a36c1fc18c0d20b822ea80173f77f2a435fdfc6d82537ed2605a2ecaae
|
4
|
+
data.tar.gz: 8f22a52c546f352010c08b73d15fe48cc658ab12a0c69251f469dc4626241923
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec85fd9e9792767aa70cc9a2cd3d8e8b87de690d52a812c3890a501b75d12a2ed5c8c76af3c49c9e68d4ee28e989895b09f62763b54ddc44fef675e29737aa20
|
7
|
+
data.tar.gz: a9467cf4aa3acf6003f15cdccb6a67b96438a54be41f511a9defb466acc387c10f8081779b339756219426a7d1a66cbe2da0fd4ac69e7fb76395ad8ef4a65705
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,23 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## 0.13.4
|
4
|
+
|
5
|
+
- Reverted change to default `printer` behavior from 0.13.3 to avoid causing a double-print to stdout as it turns out `puts` is not always needed since Rails redirects to standard out by default in `Rails.logger.debug` calls
|
6
|
+
|
7
|
+
## 0.13.3
|
8
|
+
|
9
|
+
- Update default `printer` behavior for Rails to always output via `puts` (not just in tests) in addition to `Rails.logger.debug`
|
10
|
+
- Update custom implementation of `caller` for Opal to accept args (optional `start` and `length` or alternatively `range`) just like the Ruby API
|
11
|
+
|
12
|
+
## 0.13.2
|
13
|
+
|
14
|
+
- Fix issue caused by MiniTest Rails having `IRB` constant declared despite being outside of IRB
|
15
|
+
|
16
|
+
## 0.13.1
|
17
|
+
|
18
|
+
- Support `a: '[PD]'` shortcut to passing `announcer: '[PD]'`
|
19
|
+
- Support `c: :t` shortcut to passing `caller: true`
|
20
|
+
|
3
21
|
## 0.13.0
|
4
22
|
|
5
23
|
- Support `h: :t` shortcut to passing `header: true`
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# Puts Debuggerer (debugger-less debugging FTW)
|
2
|
+
## [Featured in State of the Art Rails 2021 Edition](https://github.com/DanielVartanov/state-of-the-art-rails/tree/3d538fc6ba5287ce6c1ed15ced598ce19bbe81b5)
|
2
3
|
[](http://badge.fury.io/rb/puts_debuggerer)
|
3
4
|
[](https://travis-ci.org/AndyObtiva/puts_debuggerer)
|
4
5
|
[](https://coveralls.io/github/AndyObtiva/puts_debuggerer?branch=master)
|
@@ -114,7 +115,7 @@ Output:
|
|
114
115
|
=> "[Hard Cover] Pragmatic Ruby Book - English Version"
|
115
116
|
```
|
116
117
|
|
117
|
-
What if you would like to add a header for faster findability of groups of related pd statements? Just use the `header` option
|
118
|
+
What if you would like to add a header for faster findability of groups of related pd statements? Just use the `header` option:
|
118
119
|
|
119
120
|
```ruby
|
120
121
|
pd order_total, header: true
|
@@ -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
|
157
|
+
Wanna add a footer too? No problem!
|
149
158
|
|
150
159
|
```ruby
|
151
|
-
pd order_total, header:
|
160
|
+
pd order_total, header: true
|
152
161
|
pd order_summary
|
153
|
-
pd order_details, footer:
|
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,10 +191,10 @@ 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
|
-
Need a quick stack trace? Just use the `caller` option (you may surround with header and footer too via `wrapper`
|
197
|
+
Need a quick stack trace? Just use the `caller` option (you may surround with header and footer too via `wrapper`).
|
181
198
|
|
182
199
|
```ruby
|
183
200
|
pd order_total, caller: true, wrapper: true
|
@@ -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]]
|
@@ -285,20 +318,28 @@ There are many more options and features in [puts_debuggerer](https://rubygems.o
|
|
285
318
|
|
286
319
|
### Option 1: Bundler
|
287
320
|
|
321
|
+
This is the recommended way for installing in [Rails](rubyonrails.org) apps in addition to configuring the [`app_path` option](#putsdebuggererapp_path).
|
322
|
+
|
288
323
|
Add the following to bundler's `Gemfile`.
|
289
324
|
|
290
325
|
```ruby
|
291
|
-
gem 'puts_debuggerer', '~> 0.13.
|
326
|
+
gem 'puts_debuggerer', '~> 0.13.4'
|
327
|
+
```
|
328
|
+
|
329
|
+
Run:
|
330
|
+
|
331
|
+
```
|
332
|
+
bundle
|
292
333
|
```
|
293
334
|
|
294
|
-
|
335
|
+
Optionally, you may configure the [Rails](rubyonrails.org) initializer `config/initializers/puts_debuggerer_options.rb` with further customizations as per the [Options](#options) section below.
|
295
336
|
|
296
337
|
### Option 2: Manual
|
297
338
|
|
298
339
|
Or manually install and require library.
|
299
340
|
|
300
341
|
```bash
|
301
|
-
gem install puts_debuggerer -v0.13.
|
342
|
+
gem install puts_debuggerer -v0.13.4
|
302
343
|
```
|
303
344
|
|
304
345
|
```ruby
|
@@ -451,8 +492,15 @@ Details about all the available options are included below.
|
|
451
492
|
#### `PutsDebuggerer.app_path`
|
452
493
|
(default = `nil`)
|
453
494
|
|
454
|
-
Sets absolute application path. Makes `pd` file output relative to it.
|
455
|
-
|
495
|
+
Sets absolute application path. Makes `pd` file path output relative to it.
|
496
|
+
|
497
|
+
In [Rails](rubyonrails.org), you can add the following code to a `config/initializers/puts_debuggerer_options.rb` file to make all output relative to [Rails](rubyonrails.org) application path:
|
498
|
+
|
499
|
+
```ruby
|
500
|
+
PutsDebuggerer.app_path = Rails.root.to_s
|
501
|
+
```
|
502
|
+
|
503
|
+
Example:
|
456
504
|
|
457
505
|
```ruby
|
458
506
|
# /Users/User/finance_calculator_app/pd_test.rb # line 1
|
@@ -470,7 +518,7 @@ Example Printout:
|
|
470
518
|
```
|
471
519
|
|
472
520
|
#### `PutsDebuggerer.header`
|
473
|
-
(default = `'>'*80`)
|
521
|
+
(default = `'>'*80`) [shortcut: `h`]
|
474
522
|
|
475
523
|
Header to include at the top of every print out.
|
476
524
|
* Default value is `nil`
|
@@ -530,7 +578,7 @@ Prints out:
|
|
530
578
|
```
|
531
579
|
|
532
580
|
#### `PutsDebuggerer.footer`
|
533
|
-
(default = `'<'*80`)
|
581
|
+
(default = `'<'*80`) [shortcut: `f`]
|
534
582
|
|
535
583
|
Footer to include at the bottom of every print out.
|
536
584
|
* Default value is `nil`
|
@@ -590,7 +638,7 @@ Prints out:
|
|
590
638
|
```
|
591
639
|
|
592
640
|
#### `PutsDebuggerer.wrapper`
|
593
|
-
(default = `'*'*80`)
|
641
|
+
(default = `'*'*80`) [shortcut: `w`]
|
594
642
|
|
595
643
|
Wrapper to include at the top and bottom of every print out (both header and footer).
|
596
644
|
* Default value is `nil`
|
@@ -715,19 +763,21 @@ lambda do |output|
|
|
715
763
|
end
|
716
764
|
```
|
717
765
|
|
718
|
-
Example
|
766
|
+
Example of adding the following code to `config/initializers/puts_debuggerer_options.rb`:
|
719
767
|
|
720
768
|
```ruby
|
721
|
-
# File Name: /Users/
|
722
|
-
PutsDebuggerer.printer = lambda
|
769
|
+
# File Name: /Users/user/railsapp/config/initializers/puts_debuggerer_options.rb
|
770
|
+
PutsDebuggerer.printer = lambda do |output|
|
771
|
+
puts output
|
772
|
+
end
|
723
773
|
str = "Hello"
|
724
774
|
pd str
|
725
775
|
```
|
726
776
|
|
727
|
-
Prints out in
|
777
|
+
Prints out the following in standard out stream only (not in log files):
|
728
778
|
|
729
779
|
```bash
|
730
|
-
[PD] /Users/
|
780
|
+
[PD] /Users/user/railsapp/config/initializers/puts_debuggerer_options.rb:6
|
731
781
|
> pd str
|
732
782
|
=> Hello
|
733
783
|
```
|
@@ -762,7 +812,7 @@ Prints out:
|
|
762
812
|
```
|
763
813
|
|
764
814
|
#### `PutsDebuggerer.announcer`
|
765
|
-
(default = `"[PD]"`)
|
815
|
+
(default = `"[PD]"`) [shortcut: `a`]
|
766
816
|
|
767
817
|
Announcer (e.g. `[PD]`) to announce every print out with (default: `"[PD]"`)
|
768
818
|
|
@@ -833,7 +883,7 @@ FOOTER: ************************************************************************
|
|
833
883
|
```
|
834
884
|
|
835
885
|
#### `PutsDebuggerer.caller`
|
836
|
-
(default = nil)
|
886
|
+
(default = nil) [shortcut: `c`]
|
837
887
|
|
838
888
|
Caller backtrace included at the end of every print out
|
839
889
|
Passed an argument of true/false, nil, or depth as an integer.
|
@@ -845,15 +895,33 @@ Example:
|
|
845
895
|
|
846
896
|
```ruby
|
847
897
|
# File Name: /Users/User/sample_app/lib/sample.rb
|
848
|
-
|
849
|
-
pd (x=1)
|
898
|
+
pd (x=1), caller: 3
|
850
899
|
```
|
851
900
|
|
852
|
-
Prints out:
|
901
|
+
Prints out (fictional):
|
853
902
|
|
854
903
|
```bash
|
855
|
-
[PD] /Users/User/sample_app/lib/sample.rb:
|
856
|
-
> pd x=1
|
904
|
+
[PD] /Users/User/sample_app/lib/sample.rb:2
|
905
|
+
> pd x=1, caller: 3
|
906
|
+
=> "1"
|
907
|
+
/Users/User/sample_app/lib/master_samples.rb:368:in \`block (3 levels) in <top (required)>\'
|
908
|
+
/Users/User/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/irb/workspace.rb:87:in \`eval\'
|
909
|
+
/Users/User/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/irb/workspace.rb:87:in \`evaluate\'
|
910
|
+
/Users/User/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/irb/context.rb:381:in \`evaluate\'
|
911
|
+
```
|
912
|
+
|
913
|
+
Shortcut Example:
|
914
|
+
|
915
|
+
```ruby
|
916
|
+
# File Name: /Users/User/sample_app/lib/sample.rb
|
917
|
+
pd (x=1), c: 3
|
918
|
+
```
|
919
|
+
|
920
|
+
Prints out (fictional):
|
921
|
+
|
922
|
+
```bash
|
923
|
+
[PD] /Users/User/sample_app/lib/sample.rb:2
|
924
|
+
> pd x=1, caller: 3
|
857
925
|
=> "1"
|
858
926
|
/Users/User/sample_app/lib/master_samples.rb:368:in \`block (3 levels) in <top (required)>\'
|
859
927
|
/Users/User/.rvm/rubies/ruby-2.4.0/lib/ruby/2.4.0/irb/workspace.rb:87:in \`eval\'
|
@@ -1054,4 +1122,4 @@ Note that it ignores the configured printer when printing exceptions as it relie
|
|
1054
1122
|
|
1055
1123
|
[MIT](LICENSE.txt)
|
1056
1124
|
|
1057
|
-
Copyright (c) 2017-
|
1125
|
+
Copyright (c) 2017-2021 - Andy Maleh.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.13.
|
1
|
+
0.13.4
|
@@ -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
|
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
|
data/lib/puts_debuggerer.rb
CHANGED
@@ -65,9 +65,11 @@ module PutsDebuggerer
|
|
65
65
|
STACK_TRACE_CALL_SOURCE_FILE_REGEX_OPAL = /(http[^\)]+)/
|
66
66
|
OPTIONS = [:app_path, :source_line_count, :header, :h, :wrapper, :w, :footer, :f, :printer, :print_engine, :announcer, :formatter, :caller, :run_at]
|
67
67
|
OPTION_ALIASES = {
|
68
|
+
a: :announcer,
|
69
|
+
c: :caller,
|
68
70
|
h: :header,
|
69
71
|
f: :footer,
|
70
|
-
w: :wrapper
|
72
|
+
w: :wrapper,
|
71
73
|
}
|
72
74
|
|
73
75
|
class << self
|
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.13.
|
4
|
+
version: 0.13.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Maleh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-02-14 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
|
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
|
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
|
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
|
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.
|
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
|