dbg-rb 0.2.6 β†’ 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b59e26796df37f516bbf9e49abf36ef3e6381251efb147a8cfebc2dc3b25e859
4
- data.tar.gz: fb966c5473b1a5799fbb7c6d74823aa62821e054f8af7dfa4f6e05f39efe30fa
3
+ metadata.gz: 5770fbaace622a132343f1fbcc953b69e10c0fe851daae5bd581ac46e4305b92
4
+ data.tar.gz: b32fa55c69cb49e948492977537a52866b209bdca4ccedf788b864bff603a777
5
5
  SHA512:
6
- metadata.gz: d282afefaa8acb843fea7bd553ba3d31e323f58693ea14c96e8f14cc3c5fbf190f520d30b19521ac28636c8f02387f24dd8e15850c996a3d5a4dd7ba5ce69592
7
- data.tar.gz: 815a02500042f53cb9d8e170efd5efef323d68a994258c7b3df59de62c371958b48019ba2a83c6a73b491a8b22b1669cf70058228fdc63ac382934bc41704349
6
+ metadata.gz: f53b4203570a36a3e339be81521dc97827837b80f6b749e2ed6a91b217effd2f69d4b69cc462dc763d112f5b92e34cfe41ec44989a4570a30f8f985edea25ac0
7
+ data.tar.gz: b3c1cb8ee19a768fe74519140f5d209a40a1e17f5b474628567c25fe7d95cb50070a94f3926e212a8bb08adbfbcd9e1f4a86eccd5a7271981fdd9503d25ff396
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_base3.png)
3
+ ![Dbg base](https://github.com/pawurb/dbg-rb/raw/main/dbg_base.png)
4
4
 
5
5
  Because I wrote:
6
6
 
@@ -77,7 +77,7 @@ DbgRb.color_code = 33
77
77
  It's yellow by default. You can disable colors by running:
78
78
 
79
79
  ```ruby
80
- DbgRb.color_code= nil
80
+ DbgRb.color_code = nil
81
81
  ```
82
82
 
83
83
  ```ruby
@@ -85,7 +85,7 @@ user = User.last.as_json.slice("id", "slack_id")
85
85
  dbg("User last", :user)
86
86
  ```
87
87
 
88
- ![Dbg color](https://github.com/pawurb/dbg-rb/raw/main/dbg_base3.png)
88
+ ![Dbg color](https://github.com/pawurb/dbg-rb/raw/main/dbg_base.png)
89
89
 
90
90
  If it does not stand out enough, you can enable `dbg` highlighting:
91
91
 
@@ -96,7 +96,7 @@ require "dbg-rb"
96
96
  DbgRb.highlight!("πŸŽ‰πŸ’”πŸ’£πŸ•ΊπŸš€πŸ§¨πŸ™ˆπŸ€―πŸ₯³πŸŒˆπŸ¦„")
97
97
  ```
98
98
 
99
- ![Dbg emoji](https://github.com/pawurb/dbg-rb/raw/main/dbg_emoji2.png)
99
+ ![Dbg emoji](https://github.com/pawurb/dbg-rb/raw/main/dbg_emoji.png)
100
100
 
101
101
  You can also use `DbgRb.dbg!(*msgs)` directly or wrap it to rename the helper method:
102
102
 
data/dbg_base.png ADDED
Binary file
data/dbg_emoji.png ADDED
Binary file
data/lib/dbg-rb.rb CHANGED
@@ -51,7 +51,7 @@ module DbgRb
51
51
 
52
52
  "#{obj} = #{val}"
53
53
  rescue NameError
54
- ":#{obj}"
54
+ obj.inspect
55
55
  end
56
56
  else
57
57
  format_val(obj)
@@ -79,19 +79,35 @@ module DbgRb
79
79
  nil
80
80
  end
81
81
 
82
+ private
83
+
82
84
  def colorize(str, color_code)
83
85
  "\e[#{color_code}m#{str}\e[0m"
84
86
  end
85
87
 
86
88
  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)
89
+ if val.is_a?(Hash)
90
+ res = val.map { |k, v| [k, dbg_inspect(v, quote_str: false)] }.to_h
91
+ JSON.pretty_generate(res)
92
+ elsif val.is_a?(Array)
93
+ JSON.pretty_generate(val.map do |v|
94
+ dbg_inspect(v, quote_str: false)
95
+ end)
96
+ else
97
+ dbg_inspect(val, quote_str: true)
98
+ end
99
+ end
100
+
101
+ def dbg_inspect(obj, quote_str:)
102
+ if quote_str && obj.is_a?(String)
103
+ return obj.inspect
104
+ end
105
+
106
+ case obj
107
+ when Numeric, String
108
+ obj
93
109
  else
94
- val
110
+ obj.inspect
95
111
  end
96
112
  end
97
113
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DbgRb
4
- VERSION = "0.2.6"
4
+ VERSION = "0.2.7"
5
5
  end
data/spec/smoke_spec.rb CHANGED
@@ -5,47 +5,51 @@ require "dbg-rb"
5
5
  require "ostruct"
6
6
 
7
7
  describe DbgRb do
8
+ before do
9
+ DbgRb.color_code = nil
10
+ end
11
+
8
12
  it "variable values" do
9
- expect { dbg("123") }.to output("[spec/smoke_spec.rb:9] \"123\"\n").to_stdout
13
+ expect { dbg("123") }.to output("[spec/smoke_spec.rb:13] \"123\"\n").to_stdout
10
14
  end
11
15
 
12
16
  it "binded variables" do
13
17
  b = 123
14
- expect { dbg(:b) }.to output("[spec/smoke_spec.rb:14] b = 123\n").to_stdout
18
+ expect { dbg(:b) }.to output("[spec/smoke_spec.rb:18] b = 123\n").to_stdout
15
19
  end
16
20
 
17
21
  it "missing binded variables" do
18
22
  b = 123
19
- expect { dbg(:c) }.to output("[spec/smoke_spec.rb:19] :c\n").to_stdout
23
+ expect { dbg(:c) }.to output("[spec/smoke_spec.rb:23] :c\n").to_stdout
20
24
  end
21
25
 
22
26
  it "complex objects" do
23
27
  s = OpenStruct.new(a: 1, b: 2)
24
- expect { dbg!(s) }.to output("[spec/smoke_spec.rb:24] #<OpenStruct a=1, b=2>\n").to_stdout
28
+ expect { dbg!(s) }.to output("[spec/smoke_spec.rb:28] #<OpenStruct a=1, b=2>\n").to_stdout
25
29
  end
26
30
 
27
31
  it "binded complex objects" do
28
32
  s = OpenStruct.new(a: 1, b: 2)
29
- expect { dbg!(:s) }.to output("[spec/smoke_spec.rb:29] s = #<OpenStruct a=1, b=2>\n").to_stdout
33
+ expect { dbg!(:s) }.to output("[spec/smoke_spec.rb:33] s = #<OpenStruct a=1, b=2>\n").to_stdout
30
34
  end
31
35
 
32
36
  it "multiple msg" do
33
37
  s = OpenStruct.new(a: 1, b: 2)
34
- expect { dbg!(:s, "other msg") }.to output("[spec/smoke_spec.rb:34] s = #<OpenStruct a=1, b=2>\n[spec/smoke_spec.rb:34] \"other msg\"\n").to_stdout
38
+ expect { dbg!(:s, "other msg") }.to output("[spec/smoke_spec.rb:38] s = #<OpenStruct a=1, b=2>\n[spec/smoke_spec.rb:38] \"other msg\"\n").to_stdout
35
39
  end
36
40
 
37
41
  it "nil" do
38
- expect { dbg!(nil) }.to output("[spec/smoke_spec.rb:38] nil\n").to_stdout
42
+ expect { dbg!(nil) }.to output("[spec/smoke_spec.rb:42] nil\n").to_stdout
39
43
  end
40
44
 
41
45
  it "higlight" do
42
46
  DbgRb.highlight!
43
- expect { dbg!("123") }.to output("!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n[spec/smoke_spec.rb:43] \"123\"\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n").to_stdout
47
+ expect { dbg!("123") }.to output("!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n[spec/smoke_spec.rb:47] \"123\"\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n").to_stdout
44
48
  end
45
49
 
46
50
  it "color_code" do
47
51
  DbgRb.color_code = 31
48
- expect { dbg!(123) }.to output("\e[31m!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n[spec/smoke_spec.rb:48] 123\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!\e[0m\n").to_stdout
52
+ expect { dbg!(123) }.to output("\e[31m!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n[spec/smoke_spec.rb:52] 123\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!\e[0m\n").to_stdout
49
53
  end
50
54
 
51
55
  it "alias" do
@@ -54,11 +58,21 @@ describe DbgRb do
54
58
 
55
59
  expect {
56
60
  dbg(123)
57
- }.to output("[spec/smoke_spec.rb:56] 123\n").to_stdout
61
+ }.to output("[spec/smoke_spec.rb:60] 123\n").to_stdout
58
62
  end
59
63
 
60
64
  it "binded nil variables" do
61
65
  b = nil
62
- expect { dbg(:b) }.to output("[spec/smoke_spec.rb:62] b = nil\n").to_stdout
66
+ expect { dbg(:b) }.to output("[spec/smoke_spec.rb:66] b = nil\n").to_stdout
67
+ end
68
+
69
+ it "hashes" do
70
+ h = { a: 1, b: "2" }
71
+ expect { dbg!(h) }.to output("[spec/smoke_spec.rb:71] {\n \"a\": 1,\n \"b\": \"2\"\n}\n").to_stdout
72
+ end
73
+
74
+ it "arrays" do
75
+ a = [1, "str"]
76
+ expect { dbg!(a) }.to output("[spec/smoke_spec.rb:76] [\n 1,\n \"str\"\n]\n").to_stdout
63
77
  end
64
78
  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.6
4
+ version: 0.2.7
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-19 00:00:00.000000000 Z
11
+ date: 2024-12-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: binding_of_caller
@@ -95,9 +95,8 @@ files:
95
95
  - README.md
96
96
  - Rakefile
97
97
  - dbg-rb.gemspec
98
- - dbg_base3.png
99
- - dbg_color.png
100
- - dbg_emoji2.png
98
+ - dbg_base.png
99
+ - dbg_emoji.png
101
100
  - lib/dbg-rb.rb
102
101
  - lib/dbg_rb/version.rb
103
102
  - spec/smoke_spec.rb
data/dbg_base3.png DELETED
Binary file
data/dbg_color.png DELETED
Binary file
data/dbg_emoji2.png DELETED
Binary file