debugvisualizer 0.1.1 → 0.1.3

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: 30535723b499379235fe0c805344647f50afb9da2b975d7c26df2682440fab21
4
- data.tar.gz: 0c0956f7605a5e90d298106f7ed03ba6574fd2348ae845feb02f3de38083df42
3
+ metadata.gz: 81596abbcfa338e898076371be112d8e0544c9a3b242eb959f39e1fc71bd181e
4
+ data.tar.gz: 5dbb1660ec95cc1ed235a085aa5d4ed465b7e16fa039543ba64a08b8540366a5
5
5
  SHA512:
6
- metadata.gz: 7b65366f4b4a28d9470b6d1d1601f80ff103c337911f03985e2693689e3f8308a90fdfa7295afbd66ae5825f5cf0e5c91197a42972d89ef10720e71ba93433c5
7
- data.tar.gz: 94c5d3c22e962b79bb556af52aed072c9564ab2238371b7ce8ce31ad19c3d80877b600472d4efab0694de2cc1789d59c2903adc7b0bef4599e70dceecde2702e
6
+ metadata.gz: 624328db9fe88ecbf67d62b0e1cb04e28dfdb6b89c11d035a04e3b7cb7a94864356bca4f1f40a1bb0bb019b89d5e4e9e5ec118b334cec99934dfa3920e1b47bb
7
+ data.tar.gz: c81c5ece7c99600621b8e9ce9b589220531d9269516b2bea3a7b139aaf8eef9bedb08c9a05b0d413a1e05366fe7b135acb73d0f828be0aeacf91aa1b3e68f5a0
data/README.md CHANGED
@@ -40,3 +40,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
40
40
  ## Contributing
41
41
 
42
42
  Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/debugvisualizer.
43
+
44
+ ## Acknowledgement
45
+
46
+ [Koichi Sasada (@ko1)](https://github.com/ko1) - He reviewed API and gave me many ideas to improve `debugvisualizer`.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DebugVisualizer
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.3"
5
5
  end
@@ -4,17 +4,27 @@ require 'securerandom'
4
4
  require 'json'
5
5
 
6
6
  module DebugVisualizer
7
- def register &block
7
+ def register klass = nil, &block
8
8
  raise unless block_given?
9
9
 
10
10
  unless defined? GENERATOR
11
11
  DebugVisualizer.const_set(:GENERATOR, JSONGenerator.new)
12
12
  end
13
- GENERATOR.register_block block
13
+
14
+ if klass
15
+ GENERATOR.register_block_with_class klass, block
16
+ else
17
+ GENERATOR.register_block block
18
+ end
14
19
  end
15
20
 
16
21
  def to_debug_visualizer_protocol_json preferred_id, data
17
- GENERATOR.generate preferred_id, data
22
+ json = GENERATOR.generate preferred_id, data
23
+ if defined? ::DEBUGGER__::NaiveString
24
+ ::DEBUGGER__::NaiveString.new(json)
25
+ else
26
+ json
27
+ end
18
28
  end
19
29
 
20
30
  module_function :register, :to_debug_visualizer_protocol_json
@@ -24,12 +34,17 @@ module DebugVisualizer
24
34
 
25
35
  def initialize
26
36
  @blocks = []
37
+ @block_with_class = {}
27
38
  end
28
39
 
29
40
  def register_block block
30
41
  @blocks << block
31
42
  end
32
43
 
44
+ def register_block_with_class klass, block
45
+ @block_with_class[klass] = block
46
+ end
47
+
33
48
  def generate preferred_id, data
34
49
  extractors = []
35
50
  @blocks.each{|block|
@@ -39,6 +54,15 @@ module DebugVisualizer
39
54
  end
40
55
  }
41
56
 
57
+ @block_with_class.each{|klass, block|
58
+ if data.kind_of? klass
59
+ result = block.call(data)
60
+ if result && result[:id] && result[:data]
61
+ extractors << get_extractor(result)
62
+ end
63
+ end
64
+ }
65
+
42
66
  return JSON.generate({ kind: "NoExtractors" }) if extractors.empty?
43
67
 
44
68
  sorted = extractors.sort_by{|ex| -ex[:priority]}
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: debugvisualizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Naoto Ono
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-11-15 00:00:00.000000000 Z
11
+ date: 2022-12-02 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: debugvisualizer generates JSON based on VS Code Debug Visualizer protocol
14
14
  email: