quick-debug 0.0.2 → 0.0.3
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.
- data/README.md +10 -1
- data/lib/quick-debug.rb +25 -5
- data/lib/quick-debug/version.rb +1 -1
- metadata +10 -7
data/README.md
CHANGED
|
@@ -82,7 +82,7 @@ prints `@somevar ~> <contents of @somevar.inspect>` to STDOUT. Any object can be
|
|
|
82
82
|
```
|
|
83
83
|
D.bg(:in){'@somevar'} or D.bg(:at){'@somevar'}
|
|
84
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.
|
|
85
|
+
prints `[<caller filename, 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
86
|
|
|
87
87
|
```
|
|
88
88
|
D.lg{'@somevar'}
|
|
@@ -100,4 +100,13 @@ D.str(:in){'@somevar'} or D.str(:at){'@somevar'}
|
|
|
100
100
|
```
|
|
101
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
102
|
|
|
103
|
+
```
|
|
104
|
+
D.disable :bg
|
|
105
|
+
```
|
|
106
|
+
prevents all `D.bg` statements from printing anything. You can also pass in `:lg` or `:all` to disable `D.lg` statements or just everything respectively. You can use
|
|
107
|
+
```
|
|
108
|
+
D.enable
|
|
109
|
+
```
|
|
110
|
+
to re-enable them. It accepts the same options.
|
|
111
|
+
|
|
103
112
|
### Happy Debugging!! ###
|
data/lib/quick-debug.rb
CHANGED
|
@@ -1,22 +1,35 @@
|
|
|
1
1
|
require 'pathname'
|
|
2
|
+
require 'pp'
|
|
2
3
|
require "#{File.dirname(Pathname.new(__FILE__).realpath)}/quick-debug/version"
|
|
3
4
|
|
|
4
5
|
class D
|
|
5
6
|
@@logpath = '/tmp/quick-debug.txt'
|
|
7
|
+
@@active = {:bg => true, :lg => true}
|
|
8
|
+
|
|
9
|
+
def self.disable where
|
|
10
|
+
locations = where == :all ? [:bg, :lg] : where
|
|
11
|
+
locations.each{ |location| @@active[location] = false }
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def self.enable where
|
|
15
|
+
locations = where == :all ? [:bg, :lg] : where
|
|
16
|
+
locations.each{ |location| @@active[location] = true }
|
|
17
|
+
end
|
|
6
18
|
|
|
7
19
|
def self.logpath= path
|
|
8
20
|
@@logpath = path
|
|
9
21
|
end
|
|
10
22
|
|
|
11
23
|
def self.bg(command = nil, &block)
|
|
24
|
+
return if not @@active[:bg]
|
|
12
25
|
puts eval_inspect(caller.first, command, &block)
|
|
13
26
|
end
|
|
14
27
|
|
|
15
28
|
def self.lg(command = nil, &block)
|
|
16
|
-
|
|
29
|
+
return if not @@active[:lg]
|
|
17
30
|
timestamp = Time.now.strftime("%a %H:%M:%S")
|
|
18
31
|
File.open(@@logpath, 'a+') do |f|
|
|
19
|
-
f.puts "[#{timestamp}] #{eval_inspect(
|
|
32
|
+
f.puts "[#{timestamp}] #{eval_inspect(caller.first, command, &block)}"
|
|
20
33
|
end
|
|
21
34
|
end
|
|
22
35
|
|
|
@@ -26,15 +39,22 @@ class D
|
|
|
26
39
|
|
|
27
40
|
private
|
|
28
41
|
|
|
29
|
-
def self.eval_inspect(
|
|
42
|
+
def self.eval_inspect(caller_string, command = nil, &block)
|
|
30
43
|
outputs = []
|
|
31
44
|
if command && [:in, :at].include?(command.to_sym)
|
|
32
|
-
outputs << "[#{
|
|
45
|
+
outputs << "[#{strip_filepath caller_string}]"
|
|
33
46
|
end
|
|
34
47
|
if block
|
|
35
48
|
varname = block.call.to_s
|
|
36
|
-
outputs << "#{varname} ~> #{eval(varname, block)
|
|
49
|
+
outputs << "#{varname} ~> #{PP.pp eval(varname, block), ''}"
|
|
37
50
|
end
|
|
38
51
|
outputs.join(' ')
|
|
39
52
|
end
|
|
53
|
+
|
|
54
|
+
def self.strip_filepath caller_string
|
|
55
|
+
filepath_and_line = caller_string.split(':in ').first
|
|
56
|
+
filepath = filepath_and_line.split(':').first
|
|
57
|
+
filename = File.basename(filepath)
|
|
58
|
+
caller_string.gsub filepath, filename
|
|
59
|
+
end
|
|
40
60
|
end
|
data/lib/quick-debug/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: quick-debug
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
|
|
4
|
+
hash: 25
|
|
5
|
+
prerelease:
|
|
5
6
|
segments:
|
|
6
7
|
- 0
|
|
7
8
|
- 0
|
|
8
|
-
-
|
|
9
|
-
version: 0.0.
|
|
9
|
+
- 3
|
|
10
|
+
version: 0.0.3
|
|
10
11
|
platform: ruby
|
|
11
12
|
authors:
|
|
12
13
|
- Suan-Aik Yeo
|
|
@@ -14,8 +15,7 @@ autorequire:
|
|
|
14
15
|
bindir: bin
|
|
15
16
|
cert_chain: []
|
|
16
17
|
|
|
17
|
-
date:
|
|
18
|
-
default_executable:
|
|
18
|
+
date: 2013-01-02 00:00:00 Z
|
|
19
19
|
dependencies: []
|
|
20
20
|
|
|
21
21
|
description: Debug your Ruby code with just a few keystrokes!
|
|
@@ -35,7 +35,6 @@ files:
|
|
|
35
35
|
- lib/quick-debug.rb
|
|
36
36
|
- lib/quick-debug/version.rb
|
|
37
37
|
- quick-debug.gemspec
|
|
38
|
-
has_rdoc: true
|
|
39
38
|
homepage: ""
|
|
40
39
|
licenses: []
|
|
41
40
|
|
|
@@ -45,23 +44,27 @@ rdoc_options: []
|
|
|
45
44
|
require_paths:
|
|
46
45
|
- lib
|
|
47
46
|
required_ruby_version: !ruby/object:Gem::Requirement
|
|
47
|
+
none: false
|
|
48
48
|
requirements:
|
|
49
49
|
- - ">="
|
|
50
50
|
- !ruby/object:Gem::Version
|
|
51
|
+
hash: 3
|
|
51
52
|
segments:
|
|
52
53
|
- 0
|
|
53
54
|
version: "0"
|
|
54
55
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
56
|
+
none: false
|
|
55
57
|
requirements:
|
|
56
58
|
- - ">="
|
|
57
59
|
- !ruby/object:Gem::Version
|
|
60
|
+
hash: 3
|
|
58
61
|
segments:
|
|
59
62
|
- 0
|
|
60
63
|
version: "0"
|
|
61
64
|
requirements: []
|
|
62
65
|
|
|
63
66
|
rubyforge_project: quick-debug
|
|
64
|
-
rubygems_version: 1.
|
|
67
|
+
rubygems_version: 1.8.10
|
|
65
68
|
signing_key:
|
|
66
69
|
specification_version: 3
|
|
67
70
|
summary: Quick print-based Ruby debugging
|