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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dc71d393c746d79980c413057430f8f9e473d2746a343dc64ec3289dc6ea278e
4
- data.tar.gz: 6de928faad269dfa03dedc2e0f0606444cd3df2f8ce1f8660dbbdcf580b4a6ca
3
+ metadata.gz: 0d82a9c04865692653212313f996cf4fb9a6830527bbe4ed5558d66399b35aeb
4
+ data.tar.gz: 6ad01658fc39a212899f8d77855a4511b752c1b3da424a783f122b9223f22408
5
5
  SHA512:
6
- metadata.gz: a6c4ccb43238e5c47639339588589cdc4b175acf9cfb5ed62e332f03d9a738824891ce980f2ec8d3582ba66b7f9cc63fdb2b15868e2108f79b7dc3456810fa28
7
- data.tar.gz: 6098cf547b0efce0ef4f0751e3ae4d067b0e19864315de0de515f644da367d86b520370778eb016d9b0722a6e312e948692b6006fd2d2cfafa6bfc80c08e65cc
6
+ metadata.gz: 246eb6ddd67d12911245d1423cfec870dd72dfc5b8e513aee1c2d4b47d2d9d19398a046f6847f0d8359716c772cbe11aaaf9c71e0d5ff4934152605710d4c7e5
7
+ data.tar.gz: 312ae9d10b0c13979a18337ab645eec926a385f65307d2850a061852bf6de52ef3892fad546c32ab82c4f3cfd41a9e85e71c16b46ff144ef1dbaec6d1f5c8be0
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # dbg [![Gem Version](https://badge.fury.io/rb/dbg-rb.svg)](https://badge.fury.io/rb/dbg-rb) [![GH Actions](https://github.com/pawurb/dbg-rb/actions/workflows/ci.yml/badge.svg)](https://github.com/pawurb/dbg-rb/actions)
2
2
 
3
- ![Dbg base](https://github.com/pawurb/dbg-rb/raw/main/dbg_base.png)
3
+ ![Dbg base](https://github.com/pawurb/dbg-rb/raw/main/dbg_base2.png)
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 and line info to the debug output.
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
- user = User.last.as_json
52
- dbg(:user)
53
- # [web/users_controller.rb:10 user = {
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
- user = User.last.as_json.slice("id", "slack_id")
84
- dbg("User last", :user)
72
+ dbg(User.last(2).map(&:as_json))
85
73
  ```
86
74
 
87
- ![Dbg color](https://github.com/pawurb/dbg-rb/raw/main/dbg_base.png)
75
+ ![Dbg color](https://github.com/pawurb/dbg-rb/raw/main/dbg_base2.png)
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, String
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, String
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DbgRb
4
- VERSION = "0.3.1"
4
+ VERSION = "0.3.2"
5
5
  end
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.1
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-20 00:00:00.000000000 Z
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
- - dbg_base.png
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