puts_debuggerer 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +20 -0
  3. data/README.rdoc +66 -0
  4. data/lib/puts_debuggerer.rb +46 -0
  5. metadata +133 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7725af88945400b237c93414e5a326fd01ae0e16
4
+ data.tar.gz: 736810c4846789ee45048c7621ef034090aea238
5
+ SHA512:
6
+ metadata.gz: 3f4c8b54eea069dfcd8a0118ab128be2be829129ba696e63a4617c3e42439cad32e735835db11db15abda0feb5e0aabb22837a92d86645ad462a2abf9255e8a3
7
+ data.tar.gz: 5102841796d47eb0f5b529f9fc6fc50972cc7d96b8dc54f841cf8fee4d59be23a4d5cc8360e0b5c639d33cc9c869b5e42dfd2c98a99052b3c0ce67554ab1e0fb
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2017 Andy Maleh
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,66 @@
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.
@@ -0,0 +1,46 @@
1
+ def pd(object)
2
+ source_line = __caller_source_line__(1).strip.sub(/^[ ]*pd[ ]+/, '').gsub(/(^'|'$)/, '"')
3
+ if source_line == object.inspect.sub("\n$", '')
4
+ source_line = ''
5
+ else
6
+ source_line += '.inspect => '
7
+ end
8
+ puts "#{__caller_line_number__(1)}: #{source_line}#{object.inspect}"
9
+ end
10
+
11
+ STACK_TRACE_CALL_LINE_NUMBER_REGEX = /\:(\d+)\:in /
12
+ STACK_TRACE_CALL_SOURCE_FILE_REGEX = /[ ]*([^:]+)\:\d+\:in /
13
+
14
+ # Provides caller line number starting 1 level above caller of
15
+ # this method.
16
+ #
17
+ # Example:
18
+ # ```ruby
19
+ # puts "Print out __caller_line_number__" # line 1
20
+ # puts __caller_line_number__ # line 2
21
+ # ```
22
+ # prints out 2
23
+ def __caller_line_number__(caller_depth=0)
24
+ caller[caller_depth][STACK_TRACE_CALL_LINE_NUMBER_REGEX, 1].to_i
25
+ end
26
+
27
+
28
+ # Provides caller source line starting 1 level above caller of
29
+ # this method.
30
+ #
31
+ # Example:
32
+ # ```ruby
33
+ # puts "Print out __caller_line_number__" # line 1
34
+ # puts __caller_line_number__ # line 2
35
+ # ```
36
+ # prints out 2
37
+ def __caller_source_line__(caller_depth=0)
38
+ source_line_number = __caller_line_number__(caller_depth+1)
39
+ source_file = caller[caller_depth][STACK_TRACE_CALL_SOURCE_FILE_REGEX, 1]
40
+ source_line = nil
41
+ File.open(source_file, 'r') do |f|
42
+ lines = f.readlines
43
+ source_line = lines[source_line_number-1]
44
+ end
45
+ source_line
46
+ end
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: puts_debuggerer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Andy Maleh
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-02-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 3.5.0
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 3.5.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: rdoc
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.12'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.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.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: jeweler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 2.3.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 2.3.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: coveralls
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '='
74
+ - !ruby/object:Gem::Version
75
+ version: 0.8.5
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '='
81
+ - !ruby/object:Gem::Version
82
+ version: 0.8.5
83
+ - !ruby/object:Gem::Dependency
84
+ name: simplecov
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.10.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.10.0
97
+ description: Ruby tools for improved puts debugging, automatically displaying bonus
98
+ useful information such as line number and source code
99
+ email: andy.am@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files:
103
+ - LICENSE.txt
104
+ - README.rdoc
105
+ files:
106
+ - LICENSE.txt
107
+ - README.rdoc
108
+ - lib/puts_debuggerer.rb
109
+ homepage: http://github.com/AndyObtiva/puts_debuggerer
110
+ licenses:
111
+ - MIT
112
+ metadata: {}
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubyforge_project:
129
+ rubygems_version: 2.6.10
130
+ signing_key:
131
+ specification_version: 4
132
+ summary: Ruby tools for improved puts debugging
133
+ test_files: []