ruby-dbg 0.0.1 β 0.1.1
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 +29 -10
- data/dbg_base3.png +0 -0
- data/dbg_emoji2.png +0 -0
- data/lib/ruby-dbg.rb +10 -8
- data/lib/ruby_dbg/version.rb +1 -1
- data/ruby-dbg.gemspec +2 -3
- data/spec/smoke_spec.rb +5 -5
- metadata +7 -7
- data/dbg_emoji.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: 0ca651aa1267afde97f2e44eb08f5671b143c3cf2c3903dbac3f3f212995230e
|
4
|
+
data.tar.gz: c157e4cc54e79d8f583c7ca27b3d22d7f62f26dcbd171150df7647c1c350615b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d2b0c99545d527c6527c86dec6480e17b95b24f3ea31afe46f6bfbbdf6a1bcdc8eabf1c6e3cd53b394eac5a615887d099785b025cd6c85a8b41122740eaad09
|
7
|
+
data.tar.gz: f6cdb7be7f68846049582220fbd74b6176150952d3f9c345be0a7f8ad1609440c65f2a3bf180ab37ef9c8c696101e2a96cf764a8dcc55c827c1a803d1656f186
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
-
# Ruby dbg!
|
1
|
+
# Ruby dbg! [](https://badge.fury.io/rb/ruby-dbg) [](https://github.com/pawurb/ruby-dbg/actions)
|
2
2
|
|
3
|
+

|
4
|
+
|
3
5
|
Because I wrote:
|
4
6
|
|
5
7
|
```ruby
|
@@ -19,7 +21,9 @@ too many times already.
|
|
19
21
|
gem "ruby-dbg"
|
20
22
|
```
|
21
23
|
|
22
|
-
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
Gem adds a global `dbg!` method that you can use for puts debugging:
|
23
27
|
|
24
28
|
```ruby
|
25
29
|
require "ruby-dbg"
|
@@ -29,7 +33,7 @@ dbg!(User.last.id)
|
|
29
33
|
|
30
34
|
```
|
31
35
|
|
32
|
-
It appends
|
36
|
+
It appends a caller file and line info to the debug output.
|
33
37
|
|
34
38
|
You can use symbols to output local variable names together with their values:
|
35
39
|
|
@@ -45,9 +49,9 @@ dbg!(:a, :b)
|
|
45
49
|
Hash values are pretty printed:
|
46
50
|
|
47
51
|
```ruby
|
48
|
-
|
49
|
-
dbg!(
|
50
|
-
# [web/users_controller.rb:10 {
|
52
|
+
user = User.last.as_json
|
53
|
+
dbg!(:user)
|
54
|
+
# [web/users_controller.rb:10 user = {
|
51
55
|
# "id": 160111,
|
52
56
|
# "team_id": 1,
|
53
57
|
# "pseudonym": "Anonymous-CBWE",
|
@@ -55,31 +59,46 @@ dbg!(User.last.as_json)
|
|
55
59
|
# }
|
56
60
|
```
|
57
61
|
|
58
|
-
You can
|
62
|
+
You can color the output:
|
59
63
|
|
60
64
|
`config/initializers/ruby_dbg.rb`
|
61
65
|
```ruby
|
62
66
|
require "ruby-dbg"
|
63
67
|
|
64
|
-
RubyDBG.color_code =
|
68
|
+
RubyDBG.color_code = 35
|
65
69
|
# 31 red
|
66
70
|
# 32 green
|
67
71
|
# 33 yellow
|
68
72
|
# 34 blue
|
69
73
|
# 35 pink
|
74
|
+
# 36 light blue
|
75
|
+
```
|
76
|
+
|
77
|
+
```ruby
|
78
|
+
user = User.last.as_json.slice("id", "slack_id")
|
79
|
+
dbg!("User last", :user)
|
70
80
|
```
|
71
81
|
|
72
|
-

|
73
83
|
|
74
84
|
If it does not stand out enough, you can enable `dbg!` highlighting:
|
75
85
|
|
86
|
+
`config/initializers/ruby_dbg.rb`
|
76
87
|
```ruby
|
77
88
|
require "ruby-dbg"
|
78
89
|
|
79
90
|
RubyDBG.highlight!("πππ£πΊππ§¨ππ€―π₯³ππ¦")
|
80
91
|
```
|
81
92
|
|
82
|
-

|
94
|
+
|
95
|
+
You can also use `RubyDBG.dbg!(*msgs)` directly or wrap it to rename the helper method:
|
96
|
+
|
97
|
+
```ruby
|
98
|
+
def dd(*msgs)
|
99
|
+
RubyDBG.dbg!(*msgs)
|
100
|
+
end
|
101
|
+
```
|
83
102
|
|
84
103
|
## Status
|
85
104
|
|
data/dbg_base3.png
ADDED
Binary file
|
data/dbg_emoji2.png
ADDED
Binary file
|
data/lib/ruby-dbg.rb
CHANGED
@@ -18,7 +18,7 @@ module RubyDBG
|
|
18
18
|
"\e[#{color_code}m#{str}\e[0m"
|
19
19
|
end
|
20
20
|
|
21
|
-
def self.dbg(*
|
21
|
+
def self.dbg!(*msgs)
|
22
22
|
loc = caller_locations.first(2).last.to_s
|
23
23
|
matching_loc = loc.match(/.+(rb)\:\d+\:(in)\s/)
|
24
24
|
src = if !matching_loc.nil?
|
@@ -30,9 +30,9 @@ module RubyDBG
|
|
30
30
|
file = file.split("/").last(2).join("/")
|
31
31
|
src = "[#{file}:#{line}]"
|
32
32
|
|
33
|
-
|
33
|
+
msgs.each_with_index do |obj, i|
|
34
34
|
first = i == 0
|
35
|
-
last = i == (
|
35
|
+
last = i == (msgs.size - 1)
|
36
36
|
|
37
37
|
val = if obj.is_a?(Symbol)
|
38
38
|
begin
|
@@ -45,10 +45,9 @@ module RubyDBG
|
|
45
45
|
":#{obj}"
|
46
46
|
end
|
47
47
|
else
|
48
|
-
obj
|
48
|
+
format_val(obj)
|
49
49
|
end
|
50
50
|
|
51
|
-
val = format_val(val)
|
52
51
|
output = "#{src} #{val}"
|
53
52
|
|
54
53
|
if @@highlight
|
@@ -67,11 +66,15 @@ module RubyDBG
|
|
67
66
|
|
68
67
|
puts output
|
69
68
|
end
|
69
|
+
|
70
|
+
nil
|
70
71
|
end
|
71
72
|
|
72
73
|
def self.format_val(val)
|
73
74
|
if val.nil?
|
74
75
|
"nil"
|
76
|
+
elsif val.is_a?(String)
|
77
|
+
"\"#{val}\""
|
75
78
|
elsif val.is_a?(Hash)
|
76
79
|
JSON.pretty_generate(val)
|
77
80
|
else
|
@@ -80,7 +83,6 @@ module RubyDBG
|
|
80
83
|
end
|
81
84
|
end
|
82
85
|
|
83
|
-
def dbg!(*
|
84
|
-
RubyDBG.dbg(*
|
85
|
-
nil
|
86
|
+
def dbg!(*msgs)
|
87
|
+
RubyDBG.dbg!(*msgs)
|
86
88
|
end
|
data/lib/ruby_dbg/version.rb
CHANGED
data/ruby-dbg.gemspec
CHANGED
@@ -8,11 +8,10 @@ Gem::Specification.new do |s|
|
|
8
8
|
s.version = RubyDBG::VERSION
|
9
9
|
s.authors = ["pawurb"]
|
10
10
|
s.email = ["contact@pawelurbanek.com"]
|
11
|
-
s.summary =
|
12
|
-
s.description =
|
11
|
+
s.summary = "Simple debuging helper"
|
12
|
+
s.description = "Rust-inspired, puts debugging helper, adding caller info and optional coloring."
|
13
13
|
s.homepage = "http://github.com/pawurb/ruby-dbg"
|
14
14
|
s.files = `git ls-files`.split("\n").reject { |f| f.match?(/\.db$/) }
|
15
|
-
s.test_files = s.files.grep(%r{^(spec)/})
|
16
15
|
s.require_paths = ["lib"]
|
17
16
|
s.license = "MIT"
|
18
17
|
s.add_dependency "binding_of_caller"
|
data/spec/smoke_spec.rb
CHANGED
@@ -6,7 +6,7 @@ require "ostruct"
|
|
6
6
|
|
7
7
|
describe RubyDBG do
|
8
8
|
it "variable values" do
|
9
|
-
expect { dbg!("123") }.to output("[spec/smoke_spec.rb:9] 123\n").to_stdout
|
9
|
+
expect { dbg!("123") }.to output("[spec/smoke_spec.rb:9] \"123\"\n").to_stdout
|
10
10
|
end
|
11
11
|
|
12
12
|
it "binded variables" do
|
@@ -29,9 +29,9 @@ describe RubyDBG do
|
|
29
29
|
expect { dbg!(:s) }.to output("[spec/smoke_spec.rb:29] s = #<OpenStruct a=1, b=2>\n").to_stdout
|
30
30
|
end
|
31
31
|
|
32
|
-
it "
|
32
|
+
it "multiple msg" do
|
33
33
|
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
|
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
|
35
35
|
end
|
36
36
|
|
37
37
|
it "nil" do
|
@@ -40,11 +40,11 @@ describe RubyDBG do
|
|
40
40
|
|
41
41
|
it "higlight" do
|
42
42
|
RubyDBG.highlight!
|
43
|
-
expect { dbg!("123") }.to output("!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n[spec/smoke_spec.rb:43] 123\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n").to_stdout
|
43
|
+
expect { dbg!("123") }.to output("!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n[spec/smoke_spec.rb:43] \"123\"\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n").to_stdout
|
44
44
|
end
|
45
45
|
|
46
46
|
it "color_code" do
|
47
47
|
RubyDBG.color_code = 31
|
48
|
-
expect { dbg!(
|
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
50
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-dbg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- pawurb
|
@@ -66,7 +66,8 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
-
description:
|
69
|
+
description: Rust-inspired, puts debugging helper, adding caller info and optional
|
70
|
+
coloring.
|
70
71
|
email:
|
71
72
|
- contact@pawelurbanek.com
|
72
73
|
executables: []
|
@@ -79,8 +80,9 @@ files:
|
|
79
80
|
- LICENSE.txt
|
80
81
|
- README.md
|
81
82
|
- Rakefile
|
83
|
+
- dbg_base3.png
|
82
84
|
- dbg_color.png
|
83
|
-
-
|
85
|
+
- dbg_emoji2.png
|
84
86
|
- lib/ruby-dbg.rb
|
85
87
|
- lib/ruby_dbg/version.rb
|
86
88
|
- ruby-dbg.gemspec
|
@@ -109,7 +111,5 @@ requirements: []
|
|
109
111
|
rubygems_version: 3.5.23
|
110
112
|
signing_key:
|
111
113
|
specification_version: 4
|
112
|
-
summary: Simple
|
113
|
-
test_files:
|
114
|
-
- spec/smoke_spec.rb
|
115
|
-
- spec/spec_helper.rb
|
114
|
+
summary: Simple debuging helper
|
115
|
+
test_files: []
|
data/dbg_emoji.png
DELETED
Binary file
|