-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 926af01
Showing
8 changed files
with
178 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/.bundle/ | ||
/.yardoc | ||
/Gemfile.lock | ||
/_yardoc/ | ||
/coverage/ | ||
/doc/ | ||
/pkg/ | ||
/spec/reports/ | ||
/tmp/ | ||
*.bundle | ||
*.so | ||
*.o | ||
*.a | ||
mkmf.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
source 'https://rubygems.org' | ||
|
||
# Specify your gem's dependencies in debug_me.gemspec | ||
gemspec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
If you want it, its yours. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
# DebugMe | ||
|
||
This thing is pretty old. There are much better | ||
ways of debugging in a complex application. But, | ||
you know, I keep returning to this little method | ||
time after time. I guess that marks me as a geezer. | ||
|
||
A tool to print the labeled value of variables. | ||
|
||
Works with local, instance and class variables. | ||
|
||
## Installation | ||
|
||
Add this line to your application's Gemfile: | ||
|
||
```ruby | ||
gem 'debug_me' | ||
``` | ||
|
||
And then execute: | ||
|
||
$ bundle | ||
|
||
Or install it yourself as: | ||
|
||
$ gem install debug_me | ||
|
||
## Examples Usage | ||
|
||
```ruby | ||
require 'debug_me' | ||
include DebugMe | ||
|
||
debug_me # Prints only the header banner consisting of tag, method name, file name and line number | ||
|
||
debug_me('INFO') # Also prints only the header but with a different tag | ||
|
||
debug_me {} # prints the default header and __ALL__ variables | ||
|
||
debug_me {:just_this_variable} # prints the default header and the value of only one specific variable | ||
|
||
debug_me { [:this_one, :that_one, :that_other_one] } # prints default header and three specific variables | ||
|
||
# Use an array of symbols and strings to pass multiple variables for output | ||
# Each element of the array is 'eval'ed with the context binding of the caller | ||
debug_me(){[ :my_var, 'my_complex_var_or_method[my_var]' ]} | ||
|
||
debug_me(:header => false) {} # disables the printing of the header; prints all variables | ||
|
||
debug_me(:tag => 'MyTag', :header => false) {} # disables header, sets different tag, prints all variables | ||
|
||
debug_me('=== LOOK ===') {} # changes the tag and prints all variables with a header line | ||
|
||
debug_me('=== LOOK ===') {:@foo} # changes the tag, prints a header line and a specific instance variable | ||
|
||
debug_me('=== LOOK ===') {:@@foo} # changes the tag, prints a header line and a specific class variable | ||
|
||
debug_me(:ivar => false, :cvar => false) {} # print only the local variables with the default tag and a header line | ||
|
||
``` | ||
|
||
## Contributing | ||
|
||
1. Fork it ( https://github.com/[my-github-username]/debug_me/fork ) | ||
2. Create your feature branch (`git checkout -b my-new-feature`) | ||
3. Commit your changes (`git commit -am 'Add some feature'`) | ||
4. Push to the branch (`git push origin my-new-feature`) | ||
5. Create a new Pull Request |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
require "bundler/gem_tasks" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# coding: utf-8 | ||
lib = File.expand_path('../lib', __FILE__) | ||
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) | ||
require 'debug_me/version' | ||
|
||
Gem::Specification.new do |spec| | ||
spec.name = "debug_me" | ||
spec.version = DebugMe::VERSION | ||
spec.authors = ["Dewayne VanHoozer"] | ||
spec.email = ["dvanhoozer@gmail.com"] | ||
spec.summary = "A tool to print the labeled value of variables." | ||
spec.description = %q{This thing is pretty old. There are much better | ||
ways of debugging in a complex application. But, | ||
you know, I keep returning to this little method | ||
time after time. I guess that marks me as a geezer.} | ||
spec.homepage = "http://github.com/MadBomber/debug_me" | ||
spec.license = "You want it, its yours" | ||
|
||
spec.files = `git ls-files -z`.split("\x0") | ||
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } | ||
spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) | ||
spec.require_paths = ["lib"] | ||
|
||
spec.add_development_dependency "bundler", "~> 1.7" | ||
spec.add_development_dependency "rake", "~> 10.0" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
require 'pp' | ||
require "debug_me/version" | ||
|
||
module DebugMe | ||
|
||
def debug_me( options={}, &block ) | ||
|
||
default_options = { | ||
:tag => 'DEBUG:', # A tag to prepend to each output line | ||
:time => true, # Include a time-stamp in front of the tag | ||
:header => true, # Print a header string before printing the variables | ||
:ivar => true, # Include instance variables in the output | ||
:cvar => true, # Include class variables in the output | ||
:file => $stdout # The output file | ||
} | ||
|
||
if 'Hash' == options.class.to_s | ||
options = default_options.merge(options) | ||
else | ||
options = default_options.merge({:tag => options}) | ||
end | ||
|
||
f = options[:file] | ||
s = "" | ||
s += "#{sprintf('%010.6f', Time.now.to_f)} " if options[:time] | ||
s += " #{options[:tag]}" | ||
wf = caller # where_from under 1.8.6 its a stack trace array under 1.8.7 is a string | ||
wf = wf[0] if 'Array' == wf.class.to_s | ||
|
||
f.puts "#{s} Source: #{wf}" if options[:header] | ||
|
||
if block_given? | ||
|
||
block_value = [ block.call ].flatten.compact | ||
|
||
if block_value.empty? | ||
block_value = eval('local_variables', block.binding) | ||
block_value += [ eval('instance_variables', block.binding) ] if options[:ivar] | ||
block_value += [ self.class.send('class_variables') ] if options[:cvar] | ||
block_value = block_value.flatten.compact | ||
else | ||
block_value.map! { |v| v.to_s } | ||
end | ||
|
||
block_value.each do |v| | ||
ev = eval(v, block.binding) | ||
f.puts "#{s} #{v} -=> #{pp ev}" #.pretty_inspect}" | ||
end | ||
|
||
end ## if block_given? | ||
|
||
f.flush | ||
|
||
end ## def debug_me( options={}, &block ) | ||
|
||
# def log_me(msg, opts={}) | ||
# debug_me({:tag => msg, :header => false}.merge(opts)) | ||
# end | ||
|
||
end # module DebugMe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module DebugMe | ||
VERSION = "1.0.0" | ||
end |