puts_debuggerer 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +141 -0
- data/lib/puts_debuggerer.rb +36 -8
- metadata +4 -4
- data/README.rdoc +0 -66
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c436f4ee8d3331aeda4238d595dd1996b2ac9f6
|
4
|
+
data.tar.gz: 437c3424368501a52e3f203d06a9734a34efcdc3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c3812cc24eaabcfef0d4ad40cb01956e18617f3c92083b4336c3db5531acab59a54a85d00b56afd5d3fb12f6243c3e6f2d6bd9f70a6a1d25603cbe0aacf7509a
|
7
|
+
data.tar.gz: be7b2e10c280ef56b9690b13a7d7ea5f5fe5e3266195b7b586e8f2b638388da0322712e4fa08f00a6b24b4d9a24684b53fd7a06aedd3fb4701d734a4cb24eb92
|
data/README.md
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
# puts_debuggerer v0.2.0
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/puts_debuggerer.svg)](http://badge.fury.io/rb/puts_debuggerer)
|
3
|
+
[![Build Status](https://travis-ci.org/AndyObtiva/puts_debuggerer.svg?branch=master)](https://travis-ci.org/AndyObtiva/puts_debuggerer)
|
4
|
+
[![Coverage Status](https://coveralls.io/repos/github/AndyObtiva/puts_debuggerer/badge.svg?branch=master)](https://coveralls.io/github/AndyObtiva/puts_debuggerer?branch=master)
|
5
|
+
|
6
|
+
Ruby tools for improved puts debugging, automatically displaying bonus useful information such as file, line number and source code.
|
7
|
+
|
8
|
+
Partially inspired by this blog post:
|
9
|
+
https://tenderlovemaking.com/2016/02/05/i-am-a-puts-debuggerer.html
|
10
|
+
(Credit to Tenderlove.)
|
11
|
+
|
12
|
+
## Instructions
|
13
|
+
|
14
|
+
### Bundler
|
15
|
+
|
16
|
+
Add the following to bundler's `Gemfile`.
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
gem 'puts_debuggerer', '~> 0.2.0'
|
20
|
+
```
|
21
|
+
|
22
|
+
### Manual
|
23
|
+
|
24
|
+
Or manually install and require library.
|
25
|
+
|
26
|
+
```bash
|
27
|
+
gem install puts_debuggerer -v0.2.0
|
28
|
+
```
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
require 'puts_debuggerer'
|
32
|
+
```
|
33
|
+
|
34
|
+
### Usage
|
35
|
+
|
36
|
+
Simple invoke global `pd` method anywhere you'd like to see line number and source code with output.
|
37
|
+
If the argument is a pure string, the print out is simplified by not showing duplicate source.
|
38
|
+
|
39
|
+
Quickly find printed lines by running a find (e.g. CTRL+F) for "pd " or ".inspect => "
|
40
|
+
|
41
|
+
Happy puts debugging!
|
42
|
+
|
43
|
+
Example Code:
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
# /Users/User/finance_calculator_app/pd_test.rb # line 1
|
47
|
+
bug = 'beattle' # line 2
|
48
|
+
pd "Show me the source of the bug: #{bug}" # line 3
|
49
|
+
pd 'What line number am I?' # line 4
|
50
|
+
```
|
51
|
+
|
52
|
+
Example Printout:
|
53
|
+
|
54
|
+
```bash
|
55
|
+
pd /Users/User/finance_calculator_app/pd_test.rb:3 "Show me the source of the bug: #{bug}".inspect => "Show me the source of the bug: beattle"
|
56
|
+
pd /Users/User/finance_calculator_app/pd_test.rb:4 "What line number am I?"
|
57
|
+
```
|
58
|
+
|
59
|
+
### Options
|
60
|
+
|
61
|
+
#### `PutsDebuggerer.app_path`
|
62
|
+
|
63
|
+
Sets absolute application path. Makes `pd` file output relative to it.
|
64
|
+
If [Rails](rubyonrails.org) was detected, it is automatically defaulted to `Rails.root.to_s`
|
65
|
+
|
66
|
+
```ruby
|
67
|
+
# /Users/User/finance_calculator_app/pd_test.rb # line 1
|
68
|
+
PutsDebuggerer.app_path = File.join('/Users', 'User', 'finance_calculator_app') # line 2
|
69
|
+
bug = 'beattle' # line 3
|
70
|
+
pd "Show me the source of the bug: #{bug}" # line 4
|
71
|
+
pd 'What line number am I?' # line 5
|
72
|
+
```
|
73
|
+
|
74
|
+
Example Printout:
|
75
|
+
|
76
|
+
```bash
|
77
|
+
pd pd_test.rb:4 "Show me the source of the bug: #{bug}".inspect => "Show me the source of the bug: beattle"
|
78
|
+
pd pd_test.rb:5 "What line number am I?"
|
79
|
+
```
|
80
|
+
|
81
|
+
### Bonus
|
82
|
+
|
83
|
+
puts_debuggerer comes with the following bonus utility methods:
|
84
|
+
|
85
|
+
#### `__caller_line_number__(caller_depth=0)`
|
86
|
+
|
87
|
+
Provides caller line number starting 1 level above caller of this method (with default `caller_depth=0`).
|
88
|
+
|
89
|
+
Example:
|
90
|
+
|
91
|
+
```ruby
|
92
|
+
# lib/example.rb # line 1
|
93
|
+
puts "Print out __caller_line_number__" # line 2
|
94
|
+
puts __caller_line_number__ # line 3
|
95
|
+
```
|
96
|
+
|
97
|
+
Prints out `3`
|
98
|
+
|
99
|
+
|
100
|
+
#### `def __caller_file__(caller_depth=0)`
|
101
|
+
|
102
|
+
Provides caller file starting 1 level above caller of this method (with default `caller_depth=0`).
|
103
|
+
|
104
|
+
Example:
|
105
|
+
|
106
|
+
```ruby
|
107
|
+
# lib/example.rb
|
108
|
+
puts "Print out __caller_line_number__"
|
109
|
+
puts __caller_line_number__
|
110
|
+
```
|
111
|
+
|
112
|
+
Prints out `lib/example.rb`
|
113
|
+
|
114
|
+
#### `def __caller_source_line__(caller_depth=0)`
|
115
|
+
|
116
|
+
Provides caller source line starting 1 level above caller of this method (with default `caller_depth=0`).
|
117
|
+
|
118
|
+
Example:
|
119
|
+
|
120
|
+
```ruby
|
121
|
+
# lib/example.rb
|
122
|
+
puts "Print out __caller_line_number__"
|
123
|
+
puts __caller_line_number__
|
124
|
+
```
|
125
|
+
|
126
|
+
Prints out `puts __caller_source_line__`
|
127
|
+
|
128
|
+
## Contributing to puts_debuggerer
|
129
|
+
|
130
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
131
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
132
|
+
* Fork the project.
|
133
|
+
* Start a feature/bugfix branch.
|
134
|
+
* Commit and push until you are happy with your contribution.
|
135
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
136
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
137
|
+
|
138
|
+
## Copyright
|
139
|
+
|
140
|
+
Copyright (c) 2017 Andy Maleh. See LICENSE.txt for
|
141
|
+
further details.
|
data/lib/puts_debuggerer.rb
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
module PutsDebuggerer
|
2
|
+
class << self
|
3
|
+
attr_writer :app_path
|
4
|
+
|
5
|
+
def app_path
|
6
|
+
(@app_path || Rails.root.to_s) rescue nil
|
7
|
+
end
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
1
11
|
def pd(object)
|
2
12
|
source_line = __caller_source_line__(1).strip.sub(/^[ ]*pd[ ]+/, '').gsub(/(^'|'$)/, '"')
|
3
13
|
if source_line == object.inspect.sub("\n$", '')
|
@@ -5,7 +15,9 @@ def pd(object)
|
|
5
15
|
else
|
6
16
|
source_line += '.inspect => '
|
7
17
|
end
|
8
|
-
|
18
|
+
line_number = __caller_line_number__(1)
|
19
|
+
file = __caller_file__(1).sub(PutsDebuggerer.app_path.to_s, '')
|
20
|
+
puts "pd #{file}:#{line_number} #{source_line}#{object.inspect}"
|
9
21
|
end
|
10
22
|
|
11
23
|
STACK_TRACE_CALL_LINE_NUMBER_REGEX = /\:(\d+)\:in /
|
@@ -16,27 +28,43 @@ STACK_TRACE_CALL_SOURCE_FILE_REGEX = /[ ]*([^:]+)\:\d+\:in /
|
|
16
28
|
#
|
17
29
|
# Example:
|
18
30
|
# ```ruby
|
19
|
-
#
|
20
|
-
# puts __caller_line_number__
|
31
|
+
# # lib/example.rb # line 1
|
32
|
+
# puts "Print out __caller_line_number__" # line 2
|
33
|
+
# puts __caller_line_number__ # line 3
|
21
34
|
# ```
|
22
|
-
# prints out
|
35
|
+
# prints out `3`
|
23
36
|
def __caller_line_number__(caller_depth=0)
|
24
37
|
caller[caller_depth][STACK_TRACE_CALL_LINE_NUMBER_REGEX, 1].to_i
|
25
38
|
end
|
26
39
|
|
40
|
+
# Provides caller file starting 1 level above caller of
|
41
|
+
# this method.
|
42
|
+
#
|
43
|
+
# Example:
|
44
|
+
# ```ruby
|
45
|
+
# # lib/example.rb
|
46
|
+
# puts "Print out __caller_line_number__"
|
47
|
+
# puts __caller_line_number__
|
48
|
+
# ```
|
49
|
+
# prints out `lib/example.rb`
|
50
|
+
def __caller_file__(caller_depth=0)
|
51
|
+
caller[caller_depth][STACK_TRACE_CALL_SOURCE_FILE_REGEX, 1]
|
52
|
+
end
|
53
|
+
|
27
54
|
|
28
55
|
# Provides caller source line starting 1 level above caller of
|
29
56
|
# this method.
|
30
57
|
#
|
31
58
|
# Example:
|
32
59
|
# ```ruby
|
33
|
-
#
|
34
|
-
# puts
|
60
|
+
# # lib/example.rb
|
61
|
+
# puts "Print out __caller_line_number__"
|
62
|
+
# puts __caller_line_number__
|
35
63
|
# ```
|
36
|
-
# prints out
|
64
|
+
# prints out `puts __caller_source_line__`
|
37
65
|
def __caller_source_line__(caller_depth=0)
|
38
66
|
source_line_number = __caller_line_number__(caller_depth+1)
|
39
|
-
source_file =
|
67
|
+
source_file = __caller_file__(caller_depth+1)
|
40
68
|
source_line = nil
|
41
69
|
File.open(source_file, 'r') do |f|
|
42
70
|
lines = f.readlines
|
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.
|
4
|
+
version: 0.2.0
|
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-02-
|
11
|
+
date: 2017-02-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -101,10 +101,10 @@ executables: []
|
|
101
101
|
extensions: []
|
102
102
|
extra_rdoc_files:
|
103
103
|
- LICENSE.txt
|
104
|
-
- README.
|
104
|
+
- README.md
|
105
105
|
files:
|
106
106
|
- LICENSE.txt
|
107
|
-
- README.
|
107
|
+
- README.md
|
108
108
|
- lib/puts_debuggerer.rb
|
109
109
|
homepage: http://github.com/AndyObtiva/puts_debuggerer
|
110
110
|
licenses:
|
data/README.rdoc
DELETED
@@ -1,66 +0,0 @@
|
|
1
|
-
= puts_debuggerer v0.1.0
|
2
|
-
|
3
|
-
Ruby tools for improved puts debugging, automatically displaying bonus useful information such as line number and source code.
|
4
|
-
|
5
|
-
Partially inspired by this blog post:
|
6
|
-
https://tenderlovemaking.com/2016/02/05/i-am-a-puts-debuggerer.html
|
7
|
-
(Credit to Tenderlove.)
|
8
|
-
|
9
|
-
== Instructions
|
10
|
-
|
11
|
-
=== Bundler
|
12
|
-
|
13
|
-
Add the following to bundler's `Gemfile`.
|
14
|
-
|
15
|
-
```ruby
|
16
|
-
gem 'puts_debuggerer', '~> 0.1.0'
|
17
|
-
```
|
18
|
-
|
19
|
-
=== Manual
|
20
|
-
|
21
|
-
Or manually install and require library.
|
22
|
-
|
23
|
-
```
|
24
|
-
gem install puts_debuggerer
|
25
|
-
```
|
26
|
-
|
27
|
-
```ruby
|
28
|
-
require 'puts_debuggerer'
|
29
|
-
```
|
30
|
-
|
31
|
-
=== Usage
|
32
|
-
|
33
|
-
Simple invoke global `pd` method anywhere you'd like to see line number and source code with output.
|
34
|
-
If the argument is a pure string, the print out is simplified by not showing duplicate source.
|
35
|
-
|
36
|
-
Quickly find printed lines by running a find (e.g. CTRL+F) for "pd " or ".inspect => "
|
37
|
-
|
38
|
-
Happy puts debugging!
|
39
|
-
|
40
|
-
Example Code:
|
41
|
-
|
42
|
-
```ruby
|
43
|
-
bug = 'beattle'
|
44
|
-
pd "Show me the source of the bug: #{bug}"
|
45
|
-
pd 'What line number am I?'
|
46
|
-
```
|
47
|
-
|
48
|
-
Example Printout:
|
49
|
-
|
50
|
-
pd 2: "Show me the source of the bug: #{bug}".inspect => "Show me the source of the bug: beattle"
|
51
|
-
pd 3: "What line number am I?"
|
52
|
-
|
53
|
-
== Contributing to puts_debuggerer
|
54
|
-
|
55
|
-
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
56
|
-
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
57
|
-
* Fork the project.
|
58
|
-
* Start a feature/bugfix branch.
|
59
|
-
* Commit and push until you are happy with your contribution.
|
60
|
-
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
61
|
-
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
62
|
-
|
63
|
-
== Copyright
|
64
|
-
|
65
|
-
Copyright (c) 2017 Andy Maleh. See LICENSE.txt for
|
66
|
-
further details.
|