puts_debuggerer 0.5.0 → 0.5.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 +4 -4
- data/README.md +55 -20
- data/lib/puts_debuggerer.rb +23 -10
- metadata +11 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 88d9830281a5e05522ae9d8e5b897f16f9be2d83
|
4
|
+
data.tar.gz: 3be27b32cbb31b1e0c1b31d987c8ee99dcbd197a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fb1d343228ff5550b5b9371db25e33ae5d3d36d0d6cf22c6ba8680adf17122e89678467065d27e730bbb2011c7e106a76c675092c57ae6a1948d436b238858d8
|
7
|
+
data.tar.gz: f9dd158281412769600f08a2b31fe4a1b313bfbb5eb5f04a3c17a22c0d27ea167973cd89c56b4c0c760aa783f56dff82c68eeda4079a403bae2a2358846176f2
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# puts_debuggerer v0.5.
|
1
|
+
# puts_debuggerer v0.5.1
|
2
2
|
[](http://badge.fury.io/rb/puts_debuggerer)
|
3
3
|
[](https://travis-ci.org/AndyObtiva/puts_debuggerer)
|
4
4
|
[](https://coveralls.io/github/AndyObtiva/puts_debuggerer?branch=master)
|
@@ -8,7 +8,7 @@ statements like an umbrella in a stormy day.
|
|
8
8
|
Why not make it official and have puts debugging become its own perfectly
|
9
9
|
legitimate thing?!!
|
10
10
|
|
11
|
-
|
11
|
+
Enter puts_debuggerer. A guilt-free puts debugger Ruby gem FTW!
|
12
12
|
|
13
13
|
In other words, puts_debuggerer is a Ruby library for improved puts debugging, automatically displaying bonus useful information such as source line number and source code.
|
14
14
|
|
@@ -16,22 +16,26 @@ Partially inspired (only partially ;) by this blog post:
|
|
16
16
|
https://tenderlovemaking.com/2016/02/05/i-am-a-puts-debuggerer.html
|
17
17
|
(Credit to Tenderlove.)
|
18
18
|
|
19
|
+
Love PD?! Why not promote with [merchandise](https://www.zazzle.com/i+heart+pd+gifts)?
|
20
|
+
|
19
21
|
## Instructions
|
20
22
|
|
21
|
-
### Bundler
|
23
|
+
### Option 1: Bundler
|
22
24
|
|
23
25
|
Add the following to bundler's `Gemfile`.
|
24
26
|
|
25
27
|
```ruby
|
26
|
-
gem 'puts_debuggerer', '~> 0.5.
|
28
|
+
gem 'puts_debuggerer', '~> 0.5.1'
|
27
29
|
```
|
28
30
|
|
29
|
-
|
31
|
+
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.
|
32
|
+
|
33
|
+
### Option 2: Manual
|
30
34
|
|
31
35
|
Or manually install and require library.
|
32
36
|
|
33
37
|
```bash
|
34
|
-
gem install puts_debuggerer -v0.5.
|
38
|
+
gem install puts_debuggerer -v0.5.1
|
35
39
|
```
|
36
40
|
|
37
41
|
```ruby
|
@@ -61,19 +65,23 @@ Happy puts_debuggerering!
|
|
61
65
|
Example Code:
|
62
66
|
|
63
67
|
```ruby
|
64
|
-
# /Users/User/finance_calculator_app/pd_test.rb
|
65
|
-
bug = 'beattle'
|
66
|
-
pd
|
67
|
-
pd
|
68
|
+
# /Users/User/finance_calculator_app/pd_test.rb # line 1
|
69
|
+
bug = 'beattle' # line 2
|
70
|
+
pd 'Debugging Info:' # line 3 (literal)
|
71
|
+
pd "Show me the source of the bug: #{bug}" # line 4
|
72
|
+
pd "Show me the result of the calculation: #{(12.0/3.0)}" # line 5
|
68
73
|
```
|
69
74
|
|
70
75
|
Example Printout:
|
71
76
|
|
72
77
|
```bash
|
73
|
-
[PD] /Users/User/finance_calculator_app/pd_test.rb:3
|
78
|
+
[PD] /Users/User/finance_calculator_app/pd_test.rb:3 "Debugging Info:"
|
79
|
+
[PD] /Users/User/finance_calculator_app/pd_test.rb:4
|
74
80
|
> pd "Show me the source of the bug: #{bug}"
|
75
81
|
=> "Show me the source of the bug: beattle"
|
76
|
-
[PD] /Users/User/finance_calculator_app/pd_test.rb:
|
82
|
+
[PD] /Users/User/finance_calculator_app/pd_test.rb:5
|
83
|
+
> pd "Show me the result of the calculation: #{(12.0/3.0)}"
|
84
|
+
=> "Show me the result of the calculation: 4.0"
|
77
85
|
```
|
78
86
|
|
79
87
|
### Options
|
@@ -87,7 +95,24 @@ Global configuration is done via `PutsDebuggerer` module attribute writers.
|
|
87
95
|
On the other hand, piecemeal options can be passed to the `pd` global method as
|
88
96
|
the second argument.
|
89
97
|
|
90
|
-
Example:
|
98
|
+
Example 1:
|
99
|
+
|
100
|
+
```ruby
|
101
|
+
# File Name: /Users/User/project/piecemeal.rb
|
102
|
+
data = [1, [2, 3]]
|
103
|
+
pd data, header: true
|
104
|
+
```
|
105
|
+
|
106
|
+
Prints out:
|
107
|
+
|
108
|
+
```bash
|
109
|
+
********************************************************************************
|
110
|
+
[PD] /Users/User/project/piecemeal.rb:3
|
111
|
+
> pd data, header: true
|
112
|
+
=> [1, [2, 3]]
|
113
|
+
```
|
114
|
+
|
115
|
+
Example 2:
|
91
116
|
|
92
117
|
```ruby
|
93
118
|
# File Name: /Users/User/project/piecemeal.rb
|
@@ -101,7 +126,7 @@ Prints out:
|
|
101
126
|
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
102
127
|
-<[PD]>-
|
103
128
|
/Users/User/project/piecemeal.rb:3
|
104
|
-
> pd data
|
129
|
+
> pd data, header: '>'*80, footer: '<'*80, announcer: " -<[PD]>-\n "
|
105
130
|
=> [1, [2, 3]]
|
106
131
|
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
107
132
|
```
|
@@ -184,11 +209,10 @@ Prints out:
|
|
184
209
|
#### `PutsDebuggerer.print_engine`
|
185
210
|
(default = `:p`)
|
186
211
|
|
187
|
-
Print engine to use in object printout
|
188
|
-
|
189
|
-
(e.g. `:ap` for [awesome_print](https://github.com/awesome-print/awesome_print)).
|
212
|
+
Print engine is a global method symbol or lambda expression to use in object printout. Examples of global methods are `:p`, `:ap`, and `:pp`. An example of a lambda expression is `lambda {|o| Rails.logger.info(o)}`
|
213
|
+
|
190
214
|
Defaults to Ruby's built-in `p` method identified by the symbol `:p`.
|
191
|
-
If it finds [awesome_print](https://github.com/awesome-print/awesome_print) loaded, it defaults to `ap` as `:ap` instead.
|
215
|
+
If it finds [awesome_print](https://github.com/awesome-print/awesome_print) loaded, it defaults to `ap` as `:ap` instead. Also, if it finds Rails loaded without ap, it relies on `lambda {|o| Rails.logger.debug(o)}` as the print engine. Otherwise if both Rails and [awesome_print](https://github.com/awesome-print/awesome_print) are loaded, then it relies on `lambda {|o| Rails.logger.ap(o)}` instead
|
192
216
|
|
193
217
|
Example:
|
194
218
|
|
@@ -316,7 +340,18 @@ Prints out:
|
|
316
340
|
|
317
341
|
### Bonus
|
318
342
|
|
319
|
-
puts_debuggerer comes with
|
343
|
+
puts_debuggerer comes with a number of bonus goodies.
|
344
|
+
|
345
|
+
It comes with [awesome_print](https://github.com/awesome-print/awesome_print).
|
346
|
+
|
347
|
+
You may disable by not requiring in Ruby or by adding an explicit reference to awesome_print with `require: false` in bundler:
|
348
|
+
|
349
|
+
```ruby
|
350
|
+
gem "awesome_print", require: false
|
351
|
+
gem "puts_debugger"
|
352
|
+
```
|
353
|
+
|
354
|
+
Additionally, puts_debuggerer comes with the following bonus utility methods:
|
320
355
|
|
321
356
|
#### `__caller_line_number__(caller_depth=0)`
|
322
357
|
|
@@ -360,7 +395,7 @@ Prints out `puts __caller_source_line__`
|
|
360
395
|
|
361
396
|
## Release Notes
|
362
397
|
|
363
|
-
* v0.5.
|
398
|
+
* v0.5.1: custom formatter, caller backtrace, per-puts piecemeal options, and multi-line support
|
364
399
|
* v0.4.0: custom print engine (e.g. ap), custom announcer, and IRB support
|
365
400
|
* v0.3.0: header/footer support, multi-line printout, improved format
|
366
401
|
* v0.2.0: App path exclusion support, Rails root support, improved format
|
data/lib/puts_debuggerer.rb
CHANGED
@@ -4,7 +4,7 @@ module PutsDebuggerer
|
|
4
4
|
HEADER_DEFAULT = '*'*80
|
5
5
|
FOOTER_DEFAULT = '*'*80
|
6
6
|
PRINT_ENGINE_DEFAULT = :p
|
7
|
-
PRINT_ENGINE_MESSAGE_INVALID = 'print_engine must be a valid global method symbol (e.g. :p or :puts)'
|
7
|
+
PRINT_ENGINE_MESSAGE_INVALID = 'print_engine must be a valid global method symbol (e.g. :p or :puts) or lambda/proc'
|
8
8
|
ANNOUNCER_DEFAULT = '[PD]'
|
9
9
|
FORMATTER_DEFAULT = -> (data) {
|
10
10
|
puts data[:header] if data[:header]
|
@@ -130,7 +130,17 @@ module PutsDebuggerer
|
|
130
130
|
|
131
131
|
def print_engine=(engine)
|
132
132
|
if engine.nil?
|
133
|
-
|
133
|
+
if Object.const_defined?(:Rails)
|
134
|
+
if Object.respond_to?(:ap, 'Hello')
|
135
|
+
@print_engine = lambda {|object| Rails.logger.ap(object)}
|
136
|
+
else
|
137
|
+
@print_engine = lambda {|object| Rails.logger.debug(object)}
|
138
|
+
end
|
139
|
+
else
|
140
|
+
@print_engine = method(:ap).name rescue PRINT_ENGINE_DEFAULT
|
141
|
+
end
|
142
|
+
elsif engine.is_a?(Proc)
|
143
|
+
@print_engine = engine #TODO check that it takes one parameter or else fail fast
|
134
144
|
else
|
135
145
|
@print_engine = method(engine).name rescue raise(PRINT_ENGINE_MESSAGE_INVALID)
|
136
146
|
end
|
@@ -258,14 +268,13 @@ module PutsDebuggerer
|
|
258
268
|
send("#{option}=", value)
|
259
269
|
end
|
260
270
|
end
|
261
|
-
|
262
271
|
end
|
263
272
|
end
|
264
273
|
|
265
274
|
PutsDebuggerer.print_engine = PutsDebuggerer::PRINT_ENGINE_DEFAULT
|
266
275
|
PutsDebuggerer.announcer = PutsDebuggerer::ANNOUNCER_DEFAULT
|
267
276
|
PutsDebuggerer.formatter = PutsDebuggerer::FORMATTER_DEFAULT
|
268
|
-
PutsDebuggerer.app_path = nil
|
277
|
+
PutsDebuggerer.app_path = nil #TODO also have it set Rails root on first PD
|
269
278
|
PutsDebuggerer.caller = nil
|
270
279
|
|
271
280
|
# Prints object with bonus info such as file name, line number and source
|
@@ -345,9 +354,9 @@ end
|
|
345
354
|
# puts __caller_source_line__
|
346
355
|
#
|
347
356
|
# prints out `puts __caller_source_line__`
|
348
|
-
def __caller_source_line__(caller_depth=0)
|
349
|
-
source_line_number
|
350
|
-
source_file
|
357
|
+
def __caller_source_line__(caller_depth=0, source_file=nil, source_line_number=nil)
|
358
|
+
source_line_number ||= __caller_line_number__(caller_depth+1)
|
359
|
+
source_file ||= __caller_file__(caller_depth+1)
|
351
360
|
source_line = nil
|
352
361
|
if source_file == '(irb)'
|
353
362
|
source_line = conf.io.line(source_line_number)
|
@@ -386,10 +395,14 @@ def __build_pd_data__(object, print_engine_options=nil)
|
|
386
395
|
pd_expression: __caller_pd_expression__(depth),
|
387
396
|
object: object,
|
388
397
|
object_printer: lambda do
|
389
|
-
if
|
390
|
-
|
398
|
+
if PutsDebuggerer.print_engine.is_a?(Proc)
|
399
|
+
PutsDebuggerer.print_engine.call(object)
|
391
400
|
else
|
392
|
-
|
401
|
+
if print_engine_options.to_h.empty?
|
402
|
+
send(PutsDebuggerer.print_engine, object)
|
403
|
+
else
|
404
|
+
send(PutsDebuggerer.print_engine, object, print_engine_options) rescue send(PutsDebuggerer.print_engine, object)
|
405
|
+
end
|
393
406
|
end
|
394
407
|
end
|
395
408
|
}
|
metadata
CHANGED
@@ -1,31 +1,31 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puts_debuggerer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.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: 2017-
|
11
|
+
date: 2017-07-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: awesome_print
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
20
|
-
type: :
|
19
|
+
version: 1.7.0
|
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:
|
26
|
+
version: 1.7.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name: rspec
|
28
|
+
name: rspec
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
@@ -39,19 +39,19 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 3.5.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: rspec-mocks
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 3.5.0
|
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:
|
54
|
+
version: 3.5.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rdoc
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -125,7 +125,7 @@ dependencies:
|
|
125
125
|
description: |
|
126
126
|
Yes, many of us avoid debuggers like the plague and clamp on to our puts statements like an umbrella in a stormy day. Why not make it official and have puts debugging become its own perfectly legitimate thing?!!
|
127
127
|
|
128
|
-
|
128
|
+
Enter puts_debuggerer. A guilt-free puts debugger Ruby gem FTW!
|
129
129
|
|
130
130
|
In other words, puts_debuggerer is a Ruby library for improved puts debugging, automatically displaying bonus useful information such as source line number and source code.
|
131
131
|
|