dbg-rb 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/dbg-rb.rb +68 -52
- data/lib/dbg_rb/version.rb +1 -1
- data/spec/smoke_spec.rb +9 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 32d1a708880ea34d5100e660696d864bb1aa5176612b9684152921348ffd0269
|
4
|
+
data.tar.gz: 1b0647a7409f8c4ac564b0ae69ac33ea0a591ed2de8dff2e5ca3967dc3037c6f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 86c169bffb8ddafe0f382803b841ac0e5cbf02e86deab1b28c43b0d734e2aaac2d1df32619e5c5b8a4c384276612e059c45e60600bb18dc861354f675f4ba20f
|
7
|
+
data.tar.gz: 609749a0c676334dfe8d9bea10f4d57080dc9b38d442211134c20df37831ad13e03588b044ccdc077a3d4db70c36b95a4e66dfb9da8b729e17463c9787cf89f3
|
data/README.md
CHANGED
@@ -23,12 +23,12 @@ gem "dbg-rb"
|
|
23
23
|
|
24
24
|
## Usage
|
25
25
|
|
26
|
-
Gem adds
|
26
|
+
Gem adds global `dbg!` and `dbg` methods that you can use for puts debugging:
|
27
27
|
|
28
28
|
```ruby
|
29
29
|
require "dbg-rb"
|
30
30
|
|
31
|
-
dbg
|
31
|
+
dbg(User.last.id)
|
32
32
|
# [web/user_sessions_controller.rb:37] 1972
|
33
33
|
|
34
34
|
```
|
data/lib/dbg-rb.rb
CHANGED
@@ -3,82 +3,96 @@
|
|
3
3
|
require "binding_of_caller"
|
4
4
|
|
5
5
|
module DbgRb
|
6
|
-
@@color_code = nil
|
7
|
-
@@highlight = false
|
8
|
-
|
9
6
|
def self.color_code=(val)
|
10
|
-
|
7
|
+
Impl.color_code = val
|
11
8
|
end
|
12
9
|
|
13
10
|
def self.highlight!(wrapper = "!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
|
14
|
-
|
11
|
+
Impl.highlight!(wrapper)
|
15
12
|
end
|
16
13
|
|
17
|
-
def self.
|
18
|
-
|
14
|
+
def self.dbg!(*msgs)
|
15
|
+
Impl.new.dbg!(*msgs)
|
19
16
|
end
|
20
17
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
src = if !matching_loc.nil?
|
25
|
-
matching_loc[0][0..-5]
|
26
|
-
else
|
27
|
-
loc
|
28
|
-
end
|
29
|
-
file, line = src.split(":")
|
30
|
-
file = file.split("/").last(2).join("/")
|
31
|
-
src = "[#{file}:#{line}]"
|
18
|
+
class Impl
|
19
|
+
@@color_code = nil
|
20
|
+
@@highlight = false
|
32
21
|
|
33
|
-
|
34
|
-
|
35
|
-
|
22
|
+
def self.color_code=(val)
|
23
|
+
@@color_code = val
|
24
|
+
end
|
36
25
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
val = format_val(val)
|
26
|
+
def self.highlight!(wrapper)
|
27
|
+
@@highlight = wrapper
|
28
|
+
end
|
41
29
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
30
|
+
def dbg!(*msgs)
|
31
|
+
loc = caller_locations.first(3).last.to_s
|
32
|
+
matching_loc = loc.match(/.+(rb)\:\d+\:(in)\s/)
|
33
|
+
src = if !matching_loc.nil?
|
34
|
+
matching_loc[0][0..-5]
|
47
35
|
else
|
48
|
-
|
36
|
+
loc
|
49
37
|
end
|
38
|
+
file, line = src.split(":")
|
39
|
+
file = file.split("/").last(2).join("/")
|
40
|
+
src = "[#{file}:#{line}]"
|
41
|
+
|
42
|
+
msgs.each_with_index do |obj, i|
|
43
|
+
first = i == 0
|
44
|
+
last = i == (msgs.size - 1)
|
45
|
+
|
46
|
+
val = if obj.is_a?(Symbol)
|
47
|
+
begin
|
48
|
+
if (val = binding.of_caller(4).local_variable_get(obj))
|
49
|
+
val = format_val(val)
|
50
|
+
|
51
|
+
"#{obj} = #{val}"
|
52
|
+
end
|
53
|
+
rescue NameError
|
54
|
+
":#{obj}"
|
55
|
+
end
|
56
|
+
else
|
57
|
+
format_val(obj)
|
58
|
+
end
|
59
|
+
|
60
|
+
output = "#{src} #{val}"
|
50
61
|
|
51
|
-
|
62
|
+
if @@highlight
|
63
|
+
if first
|
64
|
+
output = "#{@@highlight}\n#{output}"
|
65
|
+
end
|
52
66
|
|
53
|
-
|
54
|
-
|
55
|
-
|
67
|
+
if last
|
68
|
+
output = "#{output}\n#{@@highlight}"
|
69
|
+
end
|
56
70
|
end
|
57
71
|
|
58
|
-
if
|
59
|
-
output =
|
72
|
+
if @@color_code != nil
|
73
|
+
output = colorize(output, @@color_code)
|
60
74
|
end
|
61
|
-
end
|
62
75
|
|
63
|
-
|
64
|
-
output = colorize(output, @@color_code)
|
76
|
+
puts output
|
65
77
|
end
|
66
78
|
|
67
|
-
|
79
|
+
nil
|
68
80
|
end
|
69
81
|
|
70
|
-
|
71
|
-
|
82
|
+
def colorize(str, color_code)
|
83
|
+
"\e[#{color_code}m#{str}\e[0m"
|
84
|
+
end
|
72
85
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
86
|
+
def format_val(val)
|
87
|
+
if val.nil?
|
88
|
+
"nil"
|
89
|
+
elsif val.is_a?(String)
|
90
|
+
"\"#{val}\""
|
91
|
+
elsif val.is_a?(Hash) || val.is_a?(Array)
|
92
|
+
JSON.pretty_generate(val)
|
93
|
+
else
|
94
|
+
val
|
95
|
+
end
|
82
96
|
end
|
83
97
|
end
|
84
98
|
end
|
@@ -86,3 +100,5 @@ end
|
|
86
100
|
def dbg!(*msgs)
|
87
101
|
DbgRb.dbg!(*msgs)
|
88
102
|
end
|
103
|
+
|
104
|
+
alias dgb dbg!
|
data/lib/dbg_rb/version.rb
CHANGED
data/spec/smoke_spec.rb
CHANGED
@@ -47,4 +47,13 @@ describe DbgRb do
|
|
47
47
|
DbgRb.color_code = 31
|
48
48
|
expect { dbg!(123) }.to output("\e[31m!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n[spec/smoke_spec.rb:48] 123\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!\e[0m\n").to_stdout
|
49
49
|
end
|
50
|
+
|
51
|
+
it "alias" do
|
52
|
+
DbgRb.highlight!(false)
|
53
|
+
DbgRb.color_code = nil
|
54
|
+
|
55
|
+
expect {
|
56
|
+
dgb(123)
|
57
|
+
}.to output("[spec/smoke_spec.rb:56] 123\n").to_stdout
|
58
|
+
end
|
50
59
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dbg-rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- pawurb
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-12-
|
11
|
+
date: 2024-12-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: binding_of_caller
|