dbg-rb 0.2.8 β†’ 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2db3ba3ac88033948685e877c1b9245f77c4f0c3b3b061d786305ea1a2059113
4
- data.tar.gz: 0412b7c4b793aabe451c622fbf293938a5e9dce9ad4ae06d4cda8604d4798df9
3
+ metadata.gz: dc71d393c746d79980c413057430f8f9e473d2746a343dc64ec3289dc6ea278e
4
+ data.tar.gz: 6de928faad269dfa03dedc2e0f0606444cd3df2f8ce1f8660dbbdcf580b4a6ca
5
5
  SHA512:
6
- metadata.gz: 5b655b3c9c88e2e973cf860f1bf8228e27075b115d6ce37e4a0903ae0a062194c15915dcb3cd851b4234dcfa119d669b57af25f563ed4f14c852b5361f67d03b
7
- data.tar.gz: d71e5a0b42c1999ab7e981ba467fa7bd19851f26c8e3f5dcd22576db306f756b95edbe04562918b372e9a1e7bfcb96e6449fc08f79dbf5db969844b6240cb994
6
+ metadata.gz: a6c4ccb43238e5c47639339588589cdc4b175acf9cfb5ed62e332f03d9a738824891ce980f2ec8d3582ba66b7f9cc63fdb2b15868e2108f79b7dc3456810fa28
7
+ data.tar.gz: 6098cf547b0efce0ef4f0751e3ae4d067b0e19864315de0de515f644da367d86b520370778eb016d9b0722a6e312e948692b6006fd2d2cfafa6bfc80c08e65cc
@@ -27,4 +27,4 @@ jobs:
27
27
  bundle install
28
28
  - name: Run tests
29
29
  run: |
30
- bundle exec rspec spec
30
+ bundle exec rake test
data/README.md CHANGED
@@ -1,4 +1,4 @@
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)
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
3
  ![Dbg base](https://github.com/pawurb/dbg-rb/raw/main/dbg_base.png)
4
4
 
@@ -16,10 +16,9 @@ too many times already.
16
16
 
17
17
  ## Installation
18
18
 
19
- `Gemfile`
20
- ```ruby
21
- gem "dbg-rb"
22
- ```
19
+ `bundle add dbg-rb`
20
+
21
+ Alternatively, you can use an inline version of `dbg-rb` without adding it to the Gemfile. Check out [this post](https://pawelurbanek.com/rails-puts-debug#inline-setup) for info on how to do it.
23
22
 
24
23
  ## Usage
25
24
 
@@ -98,14 +97,6 @@ DbgRb.highlight!("πŸŽ‰πŸ’”πŸ’£πŸ•ΊπŸš€πŸ§¨πŸ™ˆπŸ€―πŸ₯³πŸŒˆπŸ¦„")
98
97
 
99
98
  ![Dbg emoji](https://github.com/pawurb/dbg-rb/raw/main/dbg_emoji.png)
100
99
 
101
- You can also use `DbgRb.dbg!(*msgs)` directly or wrap it to rename the helper method:
102
-
103
- ```ruby
104
- def dd(*msgs)
105
- DbgRb.dbg!(*msgs)
106
- end
107
- ```
108
-
109
100
  ## Status
110
101
 
111
102
  Contributions & ideas very welcome!
data/Rakefile CHANGED
@@ -7,5 +7,6 @@ desc "Run tests"
7
7
  task :default => :test
8
8
 
9
9
  task :test do
10
- system("bundle exec rspec spec")
10
+ system("bundle exec rspec spec/main_spec.rb")
11
+ system("bundle exec rspec spec/inline_spec.rb")
11
12
  end
data/dbg-rb.gemspec CHANGED
@@ -14,7 +14,6 @@ Gem::Specification.new do |s|
14
14
  s.files = `git ls-files`.split("\n").reject { |f| f.match?(/\.db$/) }
15
15
  s.require_paths = ["lib"]
16
16
  s.license = "MIT"
17
- s.add_dependency "binding_of_caller"
18
17
  s.add_dependency "json"
19
18
  s.add_development_dependency "ostruct"
20
19
  s.add_development_dependency "rake"
data/inline/dbg_rb.rb ADDED
@@ -0,0 +1,155 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Source https://github.com/pawurb/dbg-rb
4
+ # The MIT License (MIT)
5
+
6
+ # Copyright Β© PaweΕ‚ Urbanek 2024
7
+
8
+ # Permission is hereby granted, free of charge, to any person obtaining
9
+ # a copy of this software and associated documentation files (the
10
+ # "Software"), to deal in the Software without restriction, including
11
+ # without limitation the rights to use, copy, modify, merge, publish,
12
+ # distribute, sublicense, and/or sell copies of the Software, and to
13
+ # permit persons to whom the Software is furnished to do so, subject to
14
+ # the following conditions:
15
+
16
+ # The above copyright notice and this permission notice shall be
17
+ # included in all copies or substantial portions of the Software.
18
+
19
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
23
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25
+ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26
+
27
+ require "json"
28
+
29
+ module DbgRb
30
+ def self.color_code=(val)
31
+ Impl.color_code = val
32
+ end
33
+
34
+ def self.highlight!(wrapper = "!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
35
+ Impl.highlight!(wrapper)
36
+ end
37
+
38
+ def self.dbg(*msgs)
39
+ Impl.new.dbg(*msgs)
40
+ end
41
+
42
+ class Impl
43
+ @@color_code = nil
44
+ @@highlight = false
45
+
46
+ def self.color_code=(val)
47
+ @@color_code = val
48
+ end
49
+
50
+ def self.highlight!(wrapper)
51
+ @@highlight = wrapper
52
+ end
53
+
54
+ def dbg(value)
55
+ loc = caller_locations.first(3).last
56
+ source_file = if (path = loc.absolute_path)
57
+ path.split("/").last(2).join("/")
58
+ else
59
+ loc.label
60
+ end
61
+
62
+ file = if (path = loc.absolute_path)
63
+ path.split(":").first
64
+ else
65
+ nil
66
+ end
67
+
68
+ input = nil
69
+
70
+ if file
71
+ File.open(file) do |f|
72
+ f.each_line.with_index do |line, i|
73
+ if i == loc.lineno - 1
74
+ splitby, remove_parantheses = if line.include?("dbg(")
75
+ ["dbg(", true]
76
+ else
77
+ ["dbg ", false]
78
+ end
79
+ input = line.split(splitby).last.chomp.strip
80
+ input = input.sub(/\)[^)]*\z/, "") if remove_parantheses
81
+ input
82
+ end
83
+ end
84
+ end
85
+ else
86
+ input = nil
87
+ end
88
+
89
+ line = loc.lineno
90
+ src = "[#{source_file}:#{line}]"
91
+ value = format_val(value)
92
+
93
+ val = if input.to_s == value.to_s || input.nil?
94
+ "#{value}"
95
+ else
96
+ "#{input} = #{value}"
97
+ end
98
+ output = "#{src} #{val}"
99
+
100
+ if @@highlight
101
+ output = "#{@@highlight}\n#{output}\n#{@@highlight}"
102
+ end
103
+
104
+ if @@color_code != nil
105
+ output = colorize(output, @@color_code)
106
+ end
107
+
108
+ puts output
109
+ end
110
+
111
+ private
112
+
113
+ def colorize(str, color_code)
114
+ "\e[#{color_code}m#{str}\e[0m"
115
+ end
116
+
117
+ def format_val(val)
118
+ if val.is_a?(Hash)
119
+ res = val.map { |k, v| [k, dbg_inspect(v, quote_str: false)] }.to_h
120
+ JSON.pretty_generate(res)
121
+ elsif val.is_a?(Array)
122
+ JSON.pretty_generate(val.map do |v|
123
+ dbg_inspect(v, quote_str: false)
124
+ end)
125
+ else
126
+ dbg_inspect(val, quote_str: true)
127
+ end.then do |value|
128
+ if value.is_a?(String)
129
+ value.gsub("\"nil\"", "nil")
130
+ else
131
+ value
132
+ end
133
+ end
134
+ end
135
+
136
+ def dbg_inspect(obj, quote_str:)
137
+ if quote_str && obj.is_a?(String)
138
+ return obj.inspect
139
+ end
140
+
141
+ case obj
142
+ when Numeric, String
143
+ obj
144
+ else
145
+ obj.inspect
146
+ end
147
+ end
148
+ end
149
+ end
150
+
151
+ def dbg(value)
152
+ DbgRb.dbg(value)
153
+ end
154
+
155
+ DbgRb.color_code = 33 # yellow
data/inline/sync.rb ADDED
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "fileutils"
4
+
5
+ FileUtils.cp("lib/dbg-rb.rb", "inline/dbg_rb.rb")
6
+
7
+ license = <<~LICENSE
8
+ # Source https://github.com/pawurb/dbg-rb
9
+ # The MIT License (MIT)
10
+
11
+ # Copyright Β© PaweΕ‚ Urbanek 2024
12
+
13
+ # Permission is hereby granted, free of charge, to any person obtaining
14
+ # a copy of this software and associated documentation files (the
15
+ # "Software"), to deal in the Software without restriction, including
16
+ # without limitation the rights to use, copy, modify, merge, publish,
17
+ # distribute, sublicense, and/or sell copies of the Software, and to
18
+ # permit persons to whom the Software is furnished to do so, subject to
19
+ # the following conditions:
20
+
21
+ # The above copyright notice and this permission notice shall be
22
+ # included in all copies or substantial portions of the Software.
23
+
24
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
27
+ # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
28
+ # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
29
+ # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
30
+ # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31
+ LICENSE
32
+
33
+ File.write("inline/dbg_rb.rb", File.read("inline/dbg_rb.rb").sub(/\A# frozen_string_literal: true\n/, "# frozen_string_literal: true\n\n#{license}"))
34
+
35
+ FileUtils.cp("spec/main_spec.rb", "spec/inline_spec.rb")
36
+
37
+ File.write("spec/inline_spec.rb", File.read("spec/inline_spec.rb").gsub(/main_spec/, "inline_spec").gsub("require \"dbg-rb\"", "require_relative '../inline/dbg_rb'"))
data/lib/dbg-rb.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "binding_of_caller"
4
3
  require "json"
5
4
 
6
5
  module DbgRb
@@ -12,8 +11,8 @@ module DbgRb
12
11
  Impl.highlight!(wrapper)
13
12
  end
14
13
 
15
- def self.dbg!(*msgs)
16
- Impl.new.dbg!(*msgs)
14
+ def self.dbg(*msgs)
15
+ Impl.new.dbg(*msgs)
17
16
  end
18
17
 
19
18
  class Impl
@@ -28,54 +27,61 @@ module DbgRb
28
27
  @@highlight = wrapper
29
28
  end
30
29
 
31
- def dbg!(*msgs)
30
+ def dbg(value)
32
31
  loc = caller_locations.first(3).last
33
- file = if (path = loc.absolute_path)
32
+ source_file = if (path = loc.absolute_path)
34
33
  path.split("/").last(2).join("/")
35
34
  else
36
35
  loc.label
37
36
  end
38
37
 
39
- line = loc.lineno
40
- src = "[#{file}:#{line}]"
41
-
42
- msgs.each_with_index do |obj, i|
43
- first = i == 0
44
- last = i == (msgs.size - 1)
45
-
46
- val = if obj.is_a?(Symbol)
47
- begin
48
- val = binding.of_caller(4).local_variable_get(obj)
49
- val = format_val(val)
38
+ file = if (path = loc.absolute_path)
39
+ path.split(":").first
40
+ else
41
+ nil
42
+ end
50
43
 
51
- "#{obj} = #{val}"
52
- rescue NameError
53
- obj.inspect
44
+ input = nil
45
+
46
+ if file
47
+ File.open(file) do |f|
48
+ f.each_line.with_index do |line, i|
49
+ if i == loc.lineno - 1
50
+ splitby, remove_parantheses = if line.include?("dbg(")
51
+ ["dbg(", true]
52
+ else
53
+ ["dbg ", false]
54
+ end
55
+ input = line.split(splitby).last.chomp.strip
56
+ input = input.sub(/\)[^)]*\z/, "") if remove_parantheses
57
+ input
54
58
  end
55
- else
56
- format_val(obj)
57
59
  end
60
+ end
61
+ else
62
+ input = nil
63
+ end
58
64
 
59
- output = "#{src} #{val}"
60
-
61
- if @@highlight
62
- if first
63
- output = "#{@@highlight}\n#{output}"
64
- end
65
+ line = loc.lineno
66
+ src = "[#{source_file}:#{line}]"
67
+ value = format_val(value)
65
68
 
66
- if last
67
- output = "#{output}\n#{@@highlight}"
68
- end
69
+ val = if input.to_s == value.to_s || input.nil?
70
+ "#{value}"
71
+ else
72
+ "#{input} = #{value}"
69
73
  end
74
+ output = "#{src} #{val}"
70
75
 
71
- if @@color_code != nil
72
- output = colorize(output, @@color_code)
73
- end
76
+ if @@highlight
77
+ output = "#{@@highlight}\n#{output}\n#{@@highlight}"
78
+ end
74
79
 
75
- puts output
80
+ if @@color_code != nil
81
+ output = colorize(output, @@color_code)
76
82
  end
77
83
 
78
- nil
84
+ puts output
79
85
  end
80
86
 
81
87
  private
@@ -94,6 +100,12 @@ module DbgRb
94
100
  end)
95
101
  else
96
102
  dbg_inspect(val, quote_str: true)
103
+ end.then do |value|
104
+ if value.is_a?(String)
105
+ value.gsub("\"nil\"", "nil")
106
+ else
107
+ value
108
+ end
97
109
  end
98
110
  end
99
111
 
@@ -112,10 +124,8 @@ module DbgRb
112
124
  end
113
125
  end
114
126
 
115
- def dbg!(*msgs)
116
- DbgRb.dbg!(*msgs)
127
+ def dbg(value)
128
+ DbgRb.dbg(value)
117
129
  end
118
130
 
119
131
  DbgRb.color_code = 33 # yellow
120
-
121
- alias dbg dbg!
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DbgRb
4
- VERSION = "0.2.8"
4
+ VERSION = "0.3.1"
5
5
  end
@@ -0,0 +1,119 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+ require_relative '../inline/dbg_rb'
5
+ require "ostruct"
6
+
7
+ describe DbgRb do
8
+ before do
9
+ DbgRb.color_code = nil
10
+ DbgRb.highlight!(false)
11
+ end
12
+
13
+ it "constant values" do
14
+ expect do
15
+ dbg("123")
16
+ end.to output("[spec/inline_spec.rb:15] \"123\"\n").to_stdout
17
+
18
+ expect do
19
+ dbg(123)
20
+ end.to output("[spec/inline_spec.rb:19] 123\n").to_stdout
21
+
22
+ expect do
23
+ dbg(nil)
24
+ end.to output("[spec/inline_spec.rb:23] nil\n").to_stdout
25
+
26
+ expect do
27
+ dbg "123"
28
+ end.to output("[spec/inline_spec.rb:27] \"123\"\n").to_stdout
29
+
30
+ expect do
31
+ dbg 123
32
+ end.to output("[spec/inline_spec.rb:31] 123\n").to_stdout
33
+
34
+ expect do
35
+ dbg nil
36
+ end.to output("[spec/inline_spec.rb:35] nil\n").to_stdout
37
+ end
38
+
39
+ it "variables" do
40
+ a = 123
41
+
42
+ expect do
43
+ dbg(a)
44
+ end.to output("[spec/inline_spec.rb:43] a = 123\n").to_stdout
45
+
46
+ b = "123"
47
+
48
+ expect do
49
+ dbg(b)
50
+ end.to output("[spec/inline_spec.rb:49] b = \"123\"\n").to_stdout
51
+
52
+ c = nil
53
+
54
+ expect do
55
+ dbg(c)
56
+ end.to output("[spec/inline_spec.rb:55] c = nil\n").to_stdout
57
+ end
58
+
59
+ it "complex objects" do
60
+ s = OpenStruct.new(a: 1, b: 2)
61
+
62
+ expect do
63
+ dbg(s)
64
+ end.to output("[spec/inline_spec.rb:63] s = #<OpenStruct a=1, b=2>\n").to_stdout
65
+ end
66
+
67
+ it "hashes" do
68
+ h = { a: 1, b: "2" }
69
+ expect do
70
+ dbg(h)
71
+ end.to output("[spec/inline_spec.rb:70] h = {\n \"a\": 1,\n \"b\": \"2\"\n}\n").to_stdout
72
+ end
73
+
74
+ it "arrays" do
75
+ a = [1, "str"]
76
+ expect do
77
+ dbg(a)
78
+ end.to output("[spec/inline_spec.rb:77] a = [\n 1,\n \"str\"\n]\n").to_stdout
79
+ end
80
+
81
+ it "hash formatting" do
82
+ h = { a: 1, b: "2", c: nil }
83
+ expect do
84
+ dbg(h)
85
+ end.to output("[spec/inline_spec.rb:84] h = {\n \"a\": 1,\n \"b\": \"2\",\n \"c\": nil\n}\n").to_stdout
86
+ end
87
+
88
+ it "highlight" do
89
+ DbgRb.highlight!
90
+ expect do
91
+ dbg("123")
92
+ end.to output("!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n[spec/inline_spec.rb:91] \"123\"\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n").to_stdout
93
+ end
94
+
95
+ it "color_code" do
96
+ DbgRb.color_code = 31
97
+ expect do
98
+ dbg(123)
99
+ end.to output("\e[31m[spec/inline_spec.rb:98] 123\e[0m\n").to_stdout
100
+ end
101
+
102
+ it "highlight and color_code" do
103
+ DbgRb.highlight!
104
+ DbgRb.color_code = 31
105
+ expect do
106
+ dbg(123)
107
+ end.to output("\e[31m!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n[spec/inline_spec.rb:106] 123\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!\e[0m\n").to_stdout
108
+ end
109
+
110
+ it "complex expression" do
111
+ expect do
112
+ dbg([1, 2, 3].reduce(0) { |i, agg| agg + i })
113
+ end.to output("[spec/inline_spec.rb:112] [1, 2, 3].reduce(0) { |i, agg| agg + i } = 6\n").to_stdout
114
+
115
+ expect do
116
+ dbg [1, 2, 3].reduce(0) { |i, agg| agg + i }
117
+ end.to output("[spec/inline_spec.rb:116] [1, 2, 3].reduce(0) { |i, agg| agg + i } = 6\n").to_stdout
118
+ end
119
+ end
data/spec/main_spec.rb ADDED
@@ -0,0 +1,119 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+ require "dbg-rb"
5
+ require "ostruct"
6
+
7
+ describe DbgRb do
8
+ before do
9
+ DbgRb.color_code = nil
10
+ DbgRb.highlight!(false)
11
+ end
12
+
13
+ it "constant values" do
14
+ expect do
15
+ dbg("123")
16
+ end.to output("[spec/main_spec.rb:15] \"123\"\n").to_stdout
17
+
18
+ expect do
19
+ dbg(123)
20
+ end.to output("[spec/main_spec.rb:19] 123\n").to_stdout
21
+
22
+ expect do
23
+ dbg(nil)
24
+ end.to output("[spec/main_spec.rb:23] nil\n").to_stdout
25
+
26
+ expect do
27
+ dbg "123"
28
+ end.to output("[spec/main_spec.rb:27] \"123\"\n").to_stdout
29
+
30
+ expect do
31
+ dbg 123
32
+ end.to output("[spec/main_spec.rb:31] 123\n").to_stdout
33
+
34
+ expect do
35
+ dbg nil
36
+ end.to output("[spec/main_spec.rb:35] nil\n").to_stdout
37
+ end
38
+
39
+ it "variables" do
40
+ a = 123
41
+
42
+ expect do
43
+ dbg(a)
44
+ end.to output("[spec/main_spec.rb:43] a = 123\n").to_stdout
45
+
46
+ b = "123"
47
+
48
+ expect do
49
+ dbg(b)
50
+ end.to output("[spec/main_spec.rb:49] b = \"123\"\n").to_stdout
51
+
52
+ c = nil
53
+
54
+ expect do
55
+ dbg(c)
56
+ end.to output("[spec/main_spec.rb:55] c = nil\n").to_stdout
57
+ end
58
+
59
+ it "complex objects" do
60
+ s = OpenStruct.new(a: 1, b: 2)
61
+
62
+ expect do
63
+ dbg(s)
64
+ end.to output("[spec/main_spec.rb:63] s = #<OpenStruct a=1, b=2>\n").to_stdout
65
+ end
66
+
67
+ it "hashes" do
68
+ h = { a: 1, b: "2" }
69
+ expect do
70
+ dbg(h)
71
+ end.to output("[spec/main_spec.rb:70] h = {\n \"a\": 1,\n \"b\": \"2\"\n}\n").to_stdout
72
+ end
73
+
74
+ it "arrays" do
75
+ a = [1, "str"]
76
+ expect do
77
+ dbg(a)
78
+ end.to output("[spec/main_spec.rb:77] a = [\n 1,\n \"str\"\n]\n").to_stdout
79
+ end
80
+
81
+ it "hash formatting" do
82
+ h = { a: 1, b: "2", c: nil }
83
+ expect do
84
+ dbg(h)
85
+ end.to output("[spec/main_spec.rb:84] h = {\n \"a\": 1,\n \"b\": \"2\",\n \"c\": nil\n}\n").to_stdout
86
+ end
87
+
88
+ it "highlight" do
89
+ DbgRb.highlight!
90
+ expect do
91
+ dbg("123")
92
+ end.to output("!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n[spec/main_spec.rb:91] \"123\"\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n").to_stdout
93
+ end
94
+
95
+ it "color_code" do
96
+ DbgRb.color_code = 31
97
+ expect do
98
+ dbg(123)
99
+ end.to output("\e[31m[spec/main_spec.rb:98] 123\e[0m\n").to_stdout
100
+ end
101
+
102
+ it "highlight and color_code" do
103
+ DbgRb.highlight!
104
+ DbgRb.color_code = 31
105
+ expect do
106
+ dbg(123)
107
+ end.to output("\e[31m!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n[spec/main_spec.rb:106] 123\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!\e[0m\n").to_stdout
108
+ end
109
+
110
+ it "complex expression" do
111
+ expect do
112
+ dbg([1, 2, 3].reduce(0) { |i, agg| agg + i })
113
+ end.to output("[spec/main_spec.rb:112] [1, 2, 3].reduce(0) { |i, agg| agg + i } = 6\n").to_stdout
114
+
115
+ expect do
116
+ dbg [1, 2, 3].reduce(0) { |i, agg| agg + i }
117
+ end.to output("[spec/main_spec.rb:116] [1, 2, 3].reduce(0) { |i, agg| agg + i } = 6\n").to_stdout
118
+ end
119
+ end
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dbg-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.8
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - pawurb
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-01-05 00:00:00.000000000 Z
11
+ date: 2025-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: binding_of_caller
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: json
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -111,9 +97,12 @@ files:
111
97
  - dbg-rb.gemspec
112
98
  - dbg_base.png
113
99
  - dbg_emoji.png
100
+ - inline/dbg_rb.rb
101
+ - inline/sync.rb
114
102
  - lib/dbg-rb.rb
115
103
  - lib/dbg_rb/version.rb
116
- - spec/smoke_spec.rb
104
+ - spec/inline_spec.rb
105
+ - spec/main_spec.rb
117
106
  - spec/spec_helper.rb
118
107
  homepage: http://github.com/pawurb/dbg-rb
119
108
  licenses:
data/spec/smoke_spec.rb DELETED
@@ -1,78 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
- require "dbg-rb"
5
- require "ostruct"
6
-
7
- describe DbgRb do
8
- before do
9
- DbgRb.color_code = nil
10
- end
11
-
12
- it "variable values" do
13
- expect { dbg("123") }.to output("[spec/smoke_spec.rb:13] \"123\"\n").to_stdout
14
- end
15
-
16
- it "binded variables" do
17
- b = 123
18
- expect { dbg(:b) }.to output("[spec/smoke_spec.rb:18] b = 123\n").to_stdout
19
- end
20
-
21
- it "missing binded variables" do
22
- b = 123
23
- expect { dbg(:c) }.to output("[spec/smoke_spec.rb:23] :c\n").to_stdout
24
- end
25
-
26
- it "complex objects" do
27
- s = OpenStruct.new(a: 1, b: 2)
28
- expect { dbg!(s) }.to output("[spec/smoke_spec.rb:28] #<OpenStruct a=1, b=2>\n").to_stdout
29
- end
30
-
31
- it "binded complex objects" do
32
- s = OpenStruct.new(a: 1, b: 2)
33
- expect { dbg!(:s) }.to output("[spec/smoke_spec.rb:33] s = #<OpenStruct a=1, b=2>\n").to_stdout
34
- end
35
-
36
- it "multiple msg" do
37
- s = OpenStruct.new(a: 1, b: 2)
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
39
- end
40
-
41
- it "nil" do
42
- expect { dbg!(nil) }.to output("[spec/smoke_spec.rb:42] nil\n").to_stdout
43
- end
44
-
45
- it "highlight" do
46
- DbgRb.highlight!
47
- expect { dbg!("123") }.to output("!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n[spec/smoke_spec.rb:47] \"123\"\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n").to_stdout
48
- end
49
-
50
- it "color_code" do
51
- DbgRb.color_code = 31
52
- expect { dbg!(123) }.to output("\e[31m!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n[spec/smoke_spec.rb:52] 123\n!!!!!!!!!!!!!!!!!!!!!!!!!!!!\e[0m\n").to_stdout
53
- end
54
-
55
- it "alias" do
56
- DbgRb.highlight!(false)
57
- DbgRb.color_code = nil
58
-
59
- expect {
60
- dbg(123)
61
- }.to output("[spec/smoke_spec.rb:60] 123\n").to_stdout
62
- end
63
-
64
- it "binded nil variables" do
65
- b = nil
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
77
- end
78
- end