ruby-dbg 0.0.1 β 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +20 -6
- data/lib/ruby-dbg.rb +7 -6
- data/lib/ruby_dbg/version.rb +1 -1
- data/ruby-dbg.gemspec +2 -3
- metadata +5 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f49c49046c1082711b730c0a0b1460d36672d1936c9a8419f41c5965fabf17b8
|
4
|
+
data.tar.gz: 0fe0b76b354e9244c2ac4c04f4baa9cfcf0263dc5680ae50355e1f7f3e7e7fff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f5892da2808610e1977a1fd53a247dc122a2626aac43719c2cd89604f452b080a26b68525299f4842fb72f2aa4688163897deba7a6f2b47519949e37ca0e2b7
|
7
|
+
data.tar.gz: a934c3c861b8cfe800722d659b3eccbbbc332d9941ec06a5d5540e43f1e362eece335a293241da70de31c94f7590f90c1cd83d27d26fe8dedaaf40d2aff5e175
|
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
# Ruby dbg!
|
2
|
-
|
1
|
+
# Ruby dbg! [![Gem Version](https://badge.fury.io/rb/ruby-dbg.svg)](https://badge.fury.io/rb/ruby-dbg) [![GH Actions](https://github.com/pawurb/ruby-dbg/actions/workflows/ci.yml/badge.svg)](https://github.com/pawurb/ruby-dbg/actions)
|
2
|
+
|
3
3
|
Because I wrote:
|
4
4
|
|
5
5
|
```ruby
|
@@ -19,7 +19,9 @@ too many times already.
|
|
19
19
|
gem "ruby-dbg"
|
20
20
|
```
|
21
21
|
|
22
|
-
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
Gem adds a global `dbg!` method that you can use for puts debugging:
|
23
25
|
|
24
26
|
```ruby
|
25
27
|
require "ruby-dbg"
|
@@ -29,7 +31,7 @@ dbg!(User.last.id)
|
|
29
31
|
|
30
32
|
```
|
31
33
|
|
32
|
-
It appends
|
34
|
+
It appends a caller file and line info to the debug output.
|
33
35
|
|
34
36
|
You can use symbols to output local variable names together with their values:
|
35
37
|
|
@@ -45,7 +47,6 @@ dbg!(:a, :b)
|
|
45
47
|
Hash values are pretty printed:
|
46
48
|
|
47
49
|
```ruby
|
48
|
-
|
49
50
|
dbg!(User.last.as_json)
|
50
51
|
# [web/users_controller.rb:10 {
|
51
52
|
# "id": 160111,
|
@@ -55,7 +56,7 @@ dbg!(User.last.as_json)
|
|
55
56
|
# }
|
56
57
|
```
|
57
58
|
|
58
|
-
You can
|
59
|
+
You can color the output:
|
59
60
|
|
60
61
|
`config/initializers/ruby_dbg.rb`
|
61
62
|
```ruby
|
@@ -69,10 +70,15 @@ RubyDBG.color_code = 36 # light blue
|
|
69
70
|
# 35 pink
|
70
71
|
```
|
71
72
|
|
73
|
+
```ruby
|
74
|
+
dbg!("User last", User.last.as_json.slice("id", "slack_id"))
|
75
|
+
```
|
76
|
+
|
72
77
|
![Diagnose report](https://github.com/pawurb/ruby-dbg/raw/main/dbg_color.png)
|
73
78
|
|
74
79
|
If it does not stand out enough, you can enable `dbg!` highlighting:
|
75
80
|
|
81
|
+
`config/initializers/ruby_dbg.rb`
|
76
82
|
```ruby
|
77
83
|
require "ruby-dbg"
|
78
84
|
|
@@ -81,6 +87,14 @@ RubyDBG.highlight!("πππ£πΊππ§¨ππ€―π₯³ππ¦")
|
|
81
87
|
|
82
88
|
![Diagnose report](https://github.com/pawurb/ruby-dbg/raw/main/dbg_emoji.png)
|
83
89
|
|
90
|
+
You can also use `RubyDBG.dbg!(*msgs)` directly or wrap it to rename the helper method:
|
91
|
+
|
92
|
+
```ruby
|
93
|
+
def dd(*msgs)
|
94
|
+
RubyDBG.dbg!(*msgs)
|
95
|
+
end
|
96
|
+
```
|
97
|
+
|
84
98
|
## Status
|
85
99
|
|
86
100
|
Contributions & ideas very welcome!
|
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
|
@@ -67,6 +67,8 @@ module RubyDBG
|
|
67
67
|
|
68
68
|
puts output
|
69
69
|
end
|
70
|
+
|
71
|
+
nil
|
70
72
|
end
|
71
73
|
|
72
74
|
def self.format_val(val)
|
@@ -80,7 +82,6 @@ module RubyDBG
|
|
80
82
|
end
|
81
83
|
end
|
82
84
|
|
83
|
-
def dbg!(*
|
84
|
-
RubyDBG.dbg(*
|
85
|
-
nil
|
85
|
+
def dbg!(*msgs)
|
86
|
+
RubyDBG.dbg!(*msgs)
|
86
87
|
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"
|
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.0
|
4
|
+
version: 0.1.0
|
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: []
|
@@ -109,7 +110,5 @@ requirements: []
|
|
109
110
|
rubygems_version: 3.5.23
|
110
111
|
signing_key:
|
111
112
|
specification_version: 4
|
112
|
-
summary: Simple
|
113
|
-
test_files:
|
114
|
-
- spec/smoke_spec.rb
|
115
|
-
- spec/spec_helper.rb
|
113
|
+
summary: Simple debuging helper
|
114
|
+
test_files: []
|