puts_debuggerer 0.3.0 → 0.4.0
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 +68 -10
- data/lib/puts_debuggerer.rb +79 -8
- metadata +29 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 74eb84d4e3c40ce1f68dd0142da2e4579a7cf2a7
|
4
|
+
data.tar.gz: 658504f16ce3f3522a4dba972701fb05907a5088
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 25fc5da47a71afcae5d14ce8270761ddc7a637147722c778f0a18598f5b9c8a215b595c85415516e3877c6a51ba16468727d45138c024a508023a08111282a12
|
7
|
+
data.tar.gz: 9617fe34c02aee117c6a3741fab8edfc6700549da37d7e582d73c02be1b769072c4c36b57c761f06c097f7ea5033d4aca108a3d0d173f8f97c8ce77ab7a2748f
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# puts_debuggerer v0.
|
1
|
+
# puts_debuggerer v0.4.0
|
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)
|
@@ -16,7 +16,7 @@ https://tenderlovemaking.com/2016/02/05/i-am-a-puts-debuggerer.html
|
|
16
16
|
Add the following to bundler's `Gemfile`.
|
17
17
|
|
18
18
|
```ruby
|
19
|
-
gem 'puts_debuggerer', '~> 0.
|
19
|
+
gem 'puts_debuggerer', '~> 0.4.0'
|
20
20
|
```
|
21
21
|
|
22
22
|
### Manual
|
@@ -24,7 +24,7 @@ gem 'puts_debuggerer', '~> 0.3.0'
|
|
24
24
|
Or manually install and require library.
|
25
25
|
|
26
26
|
```bash
|
27
|
-
gem install puts_debuggerer -v0.
|
27
|
+
gem install puts_debuggerer -v0.4.0
|
28
28
|
```
|
29
29
|
|
30
30
|
```ruby
|
@@ -33,15 +33,21 @@ require 'puts_debuggerer'
|
|
33
33
|
|
34
34
|
### Usage
|
35
35
|
|
36
|
-
Simply invoke global `pd` method anywhere
|
37
|
-
|
36
|
+
Simply invoke global `pd` method anywhere and it prints file, line number,
|
37
|
+
source code in addition to output (works even in IRB).
|
38
|
+
If the argument is a literal value with no interpolation, the print out is
|
39
|
+
simplified by not showing source code matching output.
|
38
40
|
|
39
41
|
Quickly locate printed lines using Find feature (e.g. CTRL+F) by looking for:
|
40
42
|
* [PD]
|
41
43
|
* file:line_number
|
42
44
|
* ruby expression.
|
43
45
|
|
44
|
-
This gives you the added benefit of easily removing your pd statements later
|
46
|
+
This gives you the added benefit of easily removing your `pd` statements later
|
47
|
+
on.
|
48
|
+
|
49
|
+
This can easily be augmented with a print engine like `awesome_print` and
|
50
|
+
customized to format output differently as per options below.
|
45
51
|
|
46
52
|
Happy puts_debuggerering!
|
47
53
|
|
@@ -65,7 +71,7 @@ Example Printout:
|
|
65
71
|
|
66
72
|
### Options
|
67
73
|
|
68
|
-
#### `PutsDebuggerer.app_path`
|
74
|
+
#### `PutsDebuggerer.app_path` (default = `nil`)
|
69
75
|
|
70
76
|
Sets absolute application path. Makes `pd` file output relative to it.
|
71
77
|
If [Rails](rubyonrails.org) was detected, it is automatically defaulted to `Rails.root.to_s`
|
@@ -87,7 +93,7 @@ Example Printout:
|
|
87
93
|
[PD] pd_test.rb:5 "What line number am I?"
|
88
94
|
```
|
89
95
|
|
90
|
-
#### `PutsDebuggerer.header`
|
96
|
+
#### `PutsDebuggerer.header` (default = `nil`)
|
91
97
|
|
92
98
|
Header to include at the top of every print out.
|
93
99
|
* Default value is `nil`
|
@@ -111,7 +117,7 @@ Prints out:
|
|
111
117
|
=> "1"
|
112
118
|
```
|
113
119
|
|
114
|
-
#### `PutsDebuggerer.footer`
|
120
|
+
#### `PutsDebuggerer.footer` (default = `nil`)
|
115
121
|
|
116
122
|
Footer to include at the bottom of every print out.
|
117
123
|
* Default value is `nil`
|
@@ -126,7 +132,7 @@ PutsDebuggerer.footer = true
|
|
126
132
|
pd (x=1)
|
127
133
|
```
|
128
134
|
|
129
|
-
Prints out
|
135
|
+
Prints out:
|
130
136
|
|
131
137
|
```bash
|
132
138
|
[PD] /Users/User/example.rb:2
|
@@ -135,6 +141,57 @@ Prints out
|
|
135
141
|
********************************************************************************
|
136
142
|
```
|
137
143
|
|
144
|
+
#### `PutsDebuggerer.print_engine` (default = `:p`)
|
145
|
+
|
146
|
+
Print engine to use in object printout (e.g. `p`, `ap`, `pp`).
|
147
|
+
It is represented by the print engine's global method name as a symbol
|
148
|
+
(e.g. `:ap` for awesome_print).
|
149
|
+
Defaults to Ruby's built-in `p` method identified by the symbol `:p`.
|
150
|
+
|
151
|
+
Example:
|
152
|
+
|
153
|
+
```ruby
|
154
|
+
# File Name: /Users/User/example.rb
|
155
|
+
require 'awesome_print'
|
156
|
+
PutsDebuggerer.print_engine = :ap
|
157
|
+
array = [1, [2, 3]]
|
158
|
+
pd array
|
159
|
+
```
|
160
|
+
|
161
|
+
Prints out:
|
162
|
+
|
163
|
+
```bash
|
164
|
+
[PD] /Users/User/example.rb:5
|
165
|
+
> (array).inspect
|
166
|
+
=> [
|
167
|
+
[0] 1,
|
168
|
+
[1] [
|
169
|
+
[0] 2,
|
170
|
+
[1] 3
|
171
|
+
]
|
172
|
+
]
|
173
|
+
```
|
174
|
+
|
175
|
+
#### `PutsDebuggerer.announcer` (default = `"[PD]"`)
|
176
|
+
|
177
|
+
Announcer (e.g. `[PD]`) to announce every print out with (default: `"[PD]"`)
|
178
|
+
|
179
|
+
Example:
|
180
|
+
|
181
|
+
```ruby
|
182
|
+
PutsDebuggerer.announcer = "*** PD ***\n "
|
183
|
+
pd (x=1)
|
184
|
+
```
|
185
|
+
|
186
|
+
Prints out:
|
187
|
+
|
188
|
+
```bash
|
189
|
+
*** PD ***
|
190
|
+
/Users/User/example.rb:2
|
191
|
+
> (x=1).inspect
|
192
|
+
=> "1"
|
193
|
+
```
|
194
|
+
|
138
195
|
### Bonus
|
139
196
|
|
140
197
|
puts_debuggerer comes with the following bonus utility methods:
|
@@ -181,6 +238,7 @@ Prints out `puts __caller_source_line__`
|
|
181
238
|
|
182
239
|
## Release Notes
|
183
240
|
|
241
|
+
* v0.4.0: custom print engine (e.g. ap), custom announcer, IRB support
|
184
242
|
* v0.3.0: header/footer support, multi-line printout, improved format
|
185
243
|
* v0.2.0: App path exclusion support, Rails root support, improved format
|
186
244
|
* v0.1.0: File/line/expression print out
|
data/lib/puts_debuggerer.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
module PutsDebuggerer
|
2
2
|
HEADER_DEFAULT = '*'*80
|
3
3
|
FOOTER_DEFAULT = '*'*80
|
4
|
+
PRINT_ENGINE_DEFAULT = :p
|
5
|
+
PRINT_ENGINE_MESSAGE_INVALID = 'print_engine must be a valid global method symbol (e.g. :p or :puts)'
|
6
|
+
ANNOUNCER_DEFAULT = '[PD]'
|
4
7
|
class << self
|
5
8
|
# Application root path to exclude when printing out file path
|
6
9
|
#
|
@@ -76,6 +79,8 @@ module PutsDebuggerer
|
|
76
79
|
def footer=(value)
|
77
80
|
if value.equal?(true)
|
78
81
|
@footer = FOOTER_DEFAULT
|
82
|
+
elsif value == ''
|
83
|
+
@footer = nil
|
79
84
|
else
|
80
85
|
@footer = value
|
81
86
|
end
|
@@ -84,9 +89,65 @@ module PutsDebuggerer
|
|
84
89
|
def footer?
|
85
90
|
!!@footer
|
86
91
|
end
|
92
|
+
|
93
|
+
# Print engine to use in object printout (e.g. `p`, `ap`, `pp`).
|
94
|
+
# It is represented by the print engine's global method name as a symbol
|
95
|
+
# (e.g. `:ap` for awesome_print).
|
96
|
+
# Defaults to Ruby's built-in `p` method identified by the symbol `:p`.
|
97
|
+
#
|
98
|
+
# Example:
|
99
|
+
#
|
100
|
+
# # File Name: /Users/User/example.rb
|
101
|
+
# require 'awesome_print'
|
102
|
+
# PutsDebuggerer.print_engine = :ap
|
103
|
+
# array = [1, [2, 3]]
|
104
|
+
# pd array
|
105
|
+
#
|
106
|
+
# Prints out
|
107
|
+
#
|
108
|
+
# [PD] /Users/User/example.rb:5
|
109
|
+
# > (array).inspect
|
110
|
+
# => [
|
111
|
+
# [0] 1,
|
112
|
+
# [1] [
|
113
|
+
# [0] 2,
|
114
|
+
# [1] 3
|
115
|
+
# ]
|
116
|
+
# ]
|
117
|
+
attr_reader :print_engine
|
118
|
+
|
119
|
+
def print_engine=(engine)
|
120
|
+
if engine.nil?
|
121
|
+
@print_engine = PRINT_ENGINE_DEFAULT
|
122
|
+
else
|
123
|
+
@print_engine = method(engine).name rescue raise(PRINT_ENGINE_MESSAGE_INVALID)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
# Announcer (e.g. [PD]) to announce every print out with (default: "[PD]")
|
128
|
+
#
|
129
|
+
# Example:
|
130
|
+
#
|
131
|
+
# PutsDebuggerer.announcer = "*** PD ***\n "
|
132
|
+
# pd (x=1)
|
133
|
+
#
|
134
|
+
# Prints out
|
135
|
+
#
|
136
|
+
# *** PD ***
|
137
|
+
# /Users/User/example.rb:2
|
138
|
+
# > (x=1).inspect
|
139
|
+
# => "1"
|
140
|
+
attr_reader :announcer
|
141
|
+
|
142
|
+
def announcer=(text)
|
143
|
+
@announcer = text.nil? ? ANNOUNCER_DEFAULT : text
|
144
|
+
end
|
87
145
|
end
|
88
146
|
end
|
89
147
|
|
148
|
+
PutsDebuggerer.print_engine = PutsDebuggerer::PRINT_ENGINE_DEFAULT
|
149
|
+
PutsDebuggerer.announcer = PutsDebuggerer::ANNOUNCER_DEFAULT
|
150
|
+
|
90
151
|
# Prints object with bonus info such as file name, line number and source
|
91
152
|
# expression. Optionally prints out header and footer.
|
92
153
|
# Lookup PutsDebuggerer attributes for more details about configuration options.
|
@@ -116,13 +177,19 @@ end
|
|
116
177
|
# > ("Show me the source of the bug: #{bug}").inspect
|
117
178
|
# => "Show me the source of the bug: beattle"
|
118
179
|
# [PD] /Users/User/finance_calculator_app/pd_test.rb:4 "What line number am I?"
|
119
|
-
def pd(object)
|
180
|
+
def pd(object, options=nil)
|
120
181
|
header = PutsDebuggerer.header? ? "#{PutsDebuggerer.header}\n" : ''
|
121
|
-
|
122
|
-
line_number = __caller_line_number__(1)
|
182
|
+
announcer = PutsDebuggerer.announcer
|
123
183
|
file = __caller_file__(1).sub(PutsDebuggerer.app_path.to_s, '')
|
124
|
-
|
125
|
-
|
184
|
+
line_number = __caller_line_number__(1)
|
185
|
+
pd_expression = __caller_pd_expression__(object)
|
186
|
+
print "#{header}#{announcer} #{file}:#{line_number}#{pd_expression} "
|
187
|
+
if options.nil? || options == {}
|
188
|
+
send(PutsDebuggerer.print_engine, object)
|
189
|
+
else
|
190
|
+
send(PutsDebuggerer.print_engine, object, options) rescue send(PutsDebuggerer.print_engine, object)
|
191
|
+
end
|
192
|
+
puts PutsDebuggerer.footer if PutsDebuggerer.footer?
|
126
193
|
end
|
127
194
|
|
128
195
|
|
@@ -169,9 +236,13 @@ def __caller_source_line__(caller_depth=0)
|
|
169
236
|
source_line_number = __caller_line_number__(caller_depth+1)
|
170
237
|
source_file = __caller_file__(caller_depth+1)
|
171
238
|
source_line = nil
|
172
|
-
|
173
|
-
|
174
|
-
|
239
|
+
if source_file == '(irb)'
|
240
|
+
source_line = conf.io.line(source_line_number)
|
241
|
+
else
|
242
|
+
File.open(source_file, 'r') do |f|
|
243
|
+
lines = f.readlines
|
244
|
+
source_line = lines[source_line_number-1]
|
245
|
+
end
|
175
246
|
end
|
176
247
|
source_line
|
177
248
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puts_debuggerer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andy Maleh
|
@@ -24,6 +24,34 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 3.5.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec-mocks
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.5.0
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.5.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: awesome_print
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.7.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.7.0
|
27
55
|
- !ruby/object:Gem::Dependency
|
28
56
|
name: rdoc
|
29
57
|
requirement: !ruby/object:Gem::Requirement
|