quick-debug 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in quick-debug.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,103 @@
1
+ Quick - debug!
2
+ ============
3
+ When debugging in Ruby, print statements are still often the best tool for the job. But how many times have you found yourself typing stuff like this over and over?
4
+
5
+ ```ruby
6
+ def main
7
+ puts "========= in main"
8
+ movie_dirs.each do |movie_dir|
9
+ Find.find(movie_dir) do |fn|
10
+ if fn.is_movie?
11
+ parent_dir = File.dirname(fn)
12
+ movie = nil
13
+ if movie_dirs.include? parent_dir or parent_dir.has_another_movie(fn)
14
+ puts "========= in if movie_dirs..."
15
+ movie = get_movie fn
16
+ puts "========= movie: #{movie.inspect}"
17
+ else
18
+ movie = get_movie(fn, true)
19
+ end
20
+ .......
21
+ ```
22
+
23
+ What if you could just do this instead?
24
+
25
+ ```ruby
26
+ def main
27
+ D.bg :in
28
+ movie_dirs.each do |movie_dir|
29
+ Find.find(movie_dir) do |fn|
30
+ if fn.is_movie?
31
+ parent_dir = File.dirname(fn)
32
+ movie = nil
33
+ if movie_dirs.include? parent_dir or parent_dir.has_another_movie(fn)
34
+ movie = get_movie fn
35
+ D.bg(:in){'movie'}
36
+ else
37
+ movie = get_movie(fn, true)
38
+ end
39
+ .......
40
+ ```
41
+
42
+ Now you can.
43
+
44
+ Installation
45
+ ------------
46
+ In your Gemfile, add:
47
+
48
+ ```
49
+ gem 'quick-debug'
50
+ ```
51
+ _or_ run this, then require the gem as such:
52
+
53
+ ```
54
+ $ gem install quick-debug
55
+ ```
56
+ ```ruby
57
+ require 'quick-debug'
58
+ ```
59
+ For especially legacy/hostile environments, or if you want to use this _really_ quickly, you can directly require the `quick-debug.rb` file in your code - it has no dependencies. If you do this often, a symlink could come in really useful. For example:
60
+
61
+ ```
62
+ $ sudo ln -s /Library/Ruby/Gems/1.8/gems/quick-debug-0.0.1/lib/quick-debug.rb /quick-debug
63
+ ```
64
+
65
+ Then, from within your code:
66
+
67
+ ```ruby
68
+ require '/quick-debug'
69
+ def main
70
+ D.bg :in
71
+ movie_dirs.each do |movie_dir|
72
+ ....
73
+ ```
74
+
75
+ Usage
76
+ -----
77
+ ```
78
+ D.bg{'@somevar'}
79
+ ```
80
+ prints `@somevar ~> <contents of @somevar.inspect>` to STDOUT. Any object can be passed in, but it must be surrounded by quotes or be made a symbol.
81
+
82
+ ```
83
+ D.bg(:in){'@somevar'} or D.bg(:at){'@somevar'}
84
+ ```
85
+ prints `[<caller method and line number>] @somevar ~> <contents of @somevar.inspect>` to STDOUT. If the block is omitted, only the caller method and line number will be printed.
86
+
87
+ ```
88
+ D.lg{'@somevar'}
89
+ D.lg(:in){'@somevar'} or D.lg(:at){'@somevar'}
90
+ ```
91
+ Same as above, but prints to `/tmp/quick-debug.txt` instead. A short timestamp is also printed at the start of each line. To change the output filepath, do
92
+
93
+ ```
94
+ D.logpath = '</some/path/log.txt>'
95
+ ```
96
+
97
+ ```
98
+ D.str{'@somevar'}
99
+ D.str(:in){'@somevar'} or D.str(:at){'@somevar'}
100
+ ```
101
+ The above methods just return the deubg output as a string, rather than printing them anywhere. This can be very useful if you need to use your own logging framework, for example: `logger.debug D.str{'@somevar'}`.
102
+
103
+ ### Happy Debugging!! ###
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,39 @@
1
+ require "#{File.dirname(__FILE__)}/quick-debug/version"
2
+
3
+ class D
4
+ @@logpath = '/tmp/quick-debug.txt'
5
+
6
+ def self.logpath= path
7
+ @@logpath = path
8
+ end
9
+
10
+ def self.bg(command = nil, &block)
11
+ puts eval_inspect(caller.first, command, &block)
12
+ end
13
+
14
+ def self.lg(command = nil, &block)
15
+ caller_method = caller.first
16
+ timestamp = Time.now.strftime("%a %H:%M:%S")
17
+ File.open(@@logpath, 'a+') do |f|
18
+ f.puts "[#{timestamp}] #{eval_inspect(caller_method, command, &block)}"
19
+ end
20
+ end
21
+
22
+ def self.str(command = nil, &block)
23
+ eval_inspect(caller.first, command, &block)
24
+ end
25
+
26
+ private
27
+
28
+ def self.eval_inspect(caller_method, command = nil, &block)
29
+ outputs = []
30
+ if command && [:in, :at].include?(command.to_sym)
31
+ outputs << "[#{caller_method}]"
32
+ end
33
+ if block
34
+ varname = block.call.to_s
35
+ outputs << "#{varname} ~> #{eval(varname, block).inspect}"
36
+ end
37
+ outputs.join(' ')
38
+ end
39
+ end
@@ -0,0 +1,3 @@
1
+ class D
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "quick-debug/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "quick-debug"
7
+ s.version = D::VERSION
8
+ s.authors = ["Suan-Aik Yeo"]
9
+ s.email = ["yeosuanaik@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Quick print-based Ruby debugging}
12
+ s.description = %q{Debug your Ruby code with just a few keystrokes!}
13
+
14
+ s.rubyforge_project = "quick-debug"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # specify any dependencies here; for example:
22
+ # s.add_development_dependency "rspec"
23
+ # s.add_runtime_dependency "rest-client"
24
+ end
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: quick-debug
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Suan-Aik Yeo
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2012-08-26 00:00:00 -05:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: Debug your Ruby code with just a few keystrokes!
22
+ email:
23
+ - yeosuanaik@gmail.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - .gitignore
32
+ - Gemfile
33
+ - README.md
34
+ - Rakefile
35
+ - lib/quick-debug.rb
36
+ - lib/quick-debug/version.rb
37
+ - quick-debug.gemspec
38
+ has_rdoc: true
39
+ homepage: ""
40
+ licenses: []
41
+
42
+ post_install_message:
43
+ rdoc_options: []
44
+
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ segments:
52
+ - 0
53
+ version: "0"
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ segments:
59
+ - 0
60
+ version: "0"
61
+ requirements: []
62
+
63
+ rubyforge_project: quick-debug
64
+ rubygems_version: 1.3.6
65
+ signing_key:
66
+ specification_version: 3
67
+ summary: Quick print-based Ruby debugging
68
+ test_files: []
69
+