dbg-rb 0.3.1 → 0.3.2
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.
- checksums.yaml +4 -4
- data/README.md +8 -20
- data/dbg_base2.png +0 -0
- data/inline/dbg_rb.rb +9 -2
- data/lib/dbg-rb.rb +9 -2
- data/lib/dbg_rb/version.rb +1 -1
- data/spec/inline_spec.rb +8 -0
- data/spec/main_spec.rb +8 -0
- metadata +3 -3
- data/dbg_base.png +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d82a9c04865692653212313f996cf4fb9a6830527bbe4ed5558d66399b35aeb
|
4
|
+
data.tar.gz: 6ad01658fc39a212899f8d77855a4511b752c1b3da424a783f122b9223f22408
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 246eb6ddd67d12911245d1423cfec870dd72dfc5b8e513aee1c2d4b47d2d9d19398a046f6847f0d8359716c772cbe11aaaf9c71e0d5ff4934152605710d4c7e5
|
7
|
+
data.tar.gz: 312ae9d10b0c13979a18337ab645eec926a385f65307d2850a061852bf6de52ef3892fad546c32ab82c4f3cfd41a9e85e71c16b46ff144ef1dbaec6d1f5c8be0
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# dbg [](https://badge.fury.io/rb/dbg-rb) [](https://github.com/pawurb/dbg-rb/actions)
|
2
2
|
|
3
|
-

|
4
4
|
|
5
5
|
Because I wrote:
|
6
6
|
|
@@ -28,29 +28,18 @@ Gem adds a global `dbg` method that you can use for puts debugging:
|
|
28
28
|
require "dbg-rb"
|
29
29
|
|
30
30
|
dbg(User.last.id)
|
31
|
-
# [web/user_sessions_controller.rb:37] 1972
|
31
|
+
# [web/user_sessions_controller.rb:37] User.last.id = 1972
|
32
32
|
|
33
33
|
```
|
34
34
|
|
35
|
-
It appends a caller file
|
36
|
-
|
37
|
-
You can use symbols to output local variable names together with their values:
|
38
|
-
|
39
|
-
```ruby
|
40
|
-
a = 1
|
41
|
-
b = 2
|
42
|
-
|
43
|
-
dbg(:a, :b)
|
44
|
-
# [models/user.rb:22] a = 1
|
45
|
-
# [models/user.rb:22] b = 2
|
46
|
-
```
|
35
|
+
It appends a caller file, line info and source expression to the debug output.
|
47
36
|
|
48
37
|
Hash values are pretty printed:
|
49
38
|
|
50
39
|
```ruby
|
51
|
-
|
52
|
-
dbg(
|
53
|
-
# [web/users_controller.rb:10
|
40
|
+
|
41
|
+
dbg(User.last.as_json)
|
42
|
+
# [web/users_controller.rb:10] User.last.as_json = {
|
54
43
|
# "id": 160111,
|
55
44
|
# "team_id": 1,
|
56
45
|
# "pseudonym": "Anonymous-CBWE",
|
@@ -80,11 +69,10 @@ DbgRb.color_code = nil
|
|
80
69
|
```
|
81
70
|
|
82
71
|
```ruby
|
83
|
-
|
84
|
-
dbg("User last", :user)
|
72
|
+
dbg(User.last(2).map(&:as_json))
|
85
73
|
```
|
86
74
|
|
87
|
-

|
88
76
|
|
89
77
|
If it does not stand out enough, you can enable `dbg` highlighting:
|
90
78
|
|
data/dbg_base2.png
ADDED
Binary file
|
data/inline/dbg_rb.rb
CHANGED
@@ -126,7 +126,7 @@ module DbgRb
|
|
126
126
|
dbg_inspect(val, quote_str: true)
|
127
127
|
end.then do |value|
|
128
128
|
if value.is_a?(String)
|
129
|
-
value.gsub("\"nil\"", "nil")
|
129
|
+
value.gsub("\"nil\"", "nil").gsub("\\", "")
|
130
130
|
else
|
131
131
|
value
|
132
132
|
end
|
@@ -139,8 +139,15 @@ module DbgRb
|
|
139
139
|
end
|
140
140
|
|
141
141
|
case obj
|
142
|
-
when Numeric
|
142
|
+
when Numeric
|
143
143
|
obj
|
144
|
+
when String
|
145
|
+
# Handle binary strings by showing their hex representation
|
146
|
+
if obj.encoding == Encoding::ASCII_8BIT
|
147
|
+
obj.bytes.map { |b| "\\x#{b.to_s(16).rjust(2, '0')}" }.join
|
148
|
+
else
|
149
|
+
obj
|
150
|
+
end
|
144
151
|
else
|
145
152
|
obj.inspect
|
146
153
|
end
|
data/lib/dbg-rb.rb
CHANGED
@@ -102,7 +102,7 @@ module DbgRb
|
|
102
102
|
dbg_inspect(val, quote_str: true)
|
103
103
|
end.then do |value|
|
104
104
|
if value.is_a?(String)
|
105
|
-
value.gsub("\"nil\"", "nil")
|
105
|
+
value.gsub("\"nil\"", "nil").gsub("\\", "")
|
106
106
|
else
|
107
107
|
value
|
108
108
|
end
|
@@ -115,8 +115,15 @@ module DbgRb
|
|
115
115
|
end
|
116
116
|
|
117
117
|
case obj
|
118
|
-
when Numeric
|
118
|
+
when Numeric
|
119
119
|
obj
|
120
|
+
when String
|
121
|
+
# Handle binary strings by showing their hex representation
|
122
|
+
if obj.encoding == Encoding::ASCII_8BIT
|
123
|
+
obj.bytes.map { |b| "\\x#{b.to_s(16).rjust(2, '0')}" }.join
|
124
|
+
else
|
125
|
+
obj
|
126
|
+
end
|
120
127
|
else
|
121
128
|
obj.inspect
|
122
129
|
end
|
data/lib/dbg_rb/version.rb
CHANGED
data/spec/inline_spec.rb
CHANGED
@@ -116,4 +116,12 @@ describe DbgRb do
|
|
116
116
|
dbg [1, 2, 3].reduce(0) { |i, agg| agg + i }
|
117
117
|
end.to output("[spec/inline_spec.rb:116] [1, 2, 3].reduce(0) { |i, agg| agg + i } = 6\n").to_stdout
|
118
118
|
end
|
119
|
+
|
120
|
+
it "binary input" do
|
121
|
+
random_bytes = Random.new.bytes(8)
|
122
|
+
|
123
|
+
expect do
|
124
|
+
dbg(random_bytes)
|
125
|
+
end.not_to raise_error
|
126
|
+
end
|
119
127
|
end
|
data/spec/main_spec.rb
CHANGED
@@ -116,4 +116,12 @@ describe DbgRb do
|
|
116
116
|
dbg [1, 2, 3].reduce(0) { |i, agg| agg + i }
|
117
117
|
end.to output("[spec/main_spec.rb:116] [1, 2, 3].reduce(0) { |i, agg| agg + i } = 6\n").to_stdout
|
118
118
|
end
|
119
|
+
|
120
|
+
it "binary input" do
|
121
|
+
random_bytes = Random.new.bytes(8)
|
122
|
+
|
123
|
+
expect do
|
124
|
+
dbg(random_bytes)
|
125
|
+
end.not_to raise_error
|
126
|
+
end
|
119
127
|
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.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- pawurb
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-05-
|
11
|
+
date: 2025-05-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -95,7 +95,7 @@ files:
|
|
95
95
|
- README.md
|
96
96
|
- Rakefile
|
97
97
|
- dbg-rb.gemspec
|
98
|
-
-
|
98
|
+
- dbg_base2.png
|
99
99
|
- dbg_emoji.png
|
100
100
|
- inline/dbg_rb.rb
|
101
101
|
- inline/sync.rb
|
data/dbg_base.png
DELETED
Binary file
|