diver_down 0.0.1.alpha5 → 0.0.1.alpha7

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: 4d5ffbc4ef413edc539a3334e4b705600a2662a37bb08a292787225ba810d875
4
- data.tar.gz: 444f687a0aa2dbc3b6b91fa248d937f282a286bb6d8709a0ec9b04312fec942a
3
+ metadata.gz: 3749e5acb9fae2d27b5267f30897c328b2a121fa1b25f89ab2dd0263af685492
4
+ data.tar.gz: 841226072e1c60faaacabcadabcf66c94bde318d7479d8090c064128be5556fe
5
5
  SHA512:
6
- metadata.gz: 350384f94a2c60506fffe52d43bdd705bf048cf6d62dfdd60f3d315fe89e9647896f1b9fc6491dc5bfeccd475c970580bd1ee4599e843a79e8bfd17d4d1f0764
7
- data.tar.gz: e16ffe92d2df53c258e7fc4a295411f7f35611334af421d9e78b7fcc1b9e7b77190cdf568ca3fd0fa82a0340cd04175e2bb631cdfee3467bfdc31eb6f687e7c8
6
+ metadata.gz: 80753b14f48811fa05d84b75f303d17335701f82fc04ead701c8e8b53473f0d9860bf7e78a25201e0c9bc9c58af89764350f023c3ea4310c7b3cb6c6b0ab93a9
7
+ data.tar.gz: 5ec6ec0814d825864fb062ec0db92f3f7d6df8949795ac5c4f6299b302219e5f50f6ba9f8f8590b8ac123c268f8a04ac268a95e0af6638084ff13b62859d603a
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DiverDown
4
- VERSION = '0.0.1.alpha5'
4
+ VERSION = '0.0.1.alpha7'
5
5
  end
@@ -161,7 +161,7 @@ module DiverDown
161
161
 
162
162
  # @return [String]
163
163
  def to_s
164
- io.puts %(strict digraph "#{definition.title}" {)
164
+ io.puts %(strict digraph "#{escape_quote(definition.title)}" {)
165
165
  io.indented do
166
166
  io.puts('compound=true') if @compound
167
167
  io.puts('concentrate=true') if @concentrate
@@ -169,9 +169,7 @@ module DiverDown
169
169
  if @only_module
170
170
  render_only_modules
171
171
  else
172
- definition.sources.sort_by(&:source_name).each do
173
- insert_source(_1)
174
- end
172
+ render_sources
175
173
  end
176
174
  end
177
175
  io.puts '}'
@@ -214,11 +212,11 @@ module DiverDown
214
212
  module_names = specific_module_names[0..index]
215
213
  module_name = specific_module_names[index]
216
214
 
217
- io.puts %(subgraph "#{module_label(module_names)}" {)
215
+ io.puts %(subgraph "#{escape_quote(module_label(module_names))}" {)
218
216
  io.indented do
219
217
  io.puts %(id="#{@metadata_store.issue_modules_id(module_names)}")
220
- io.puts %(label="#{module_name}")
221
- io.puts %("#{module_name}" #{build_attributes(label: module_name, id: @metadata_store.issue_modules_id(module_names))})
218
+ io.puts %(label="#{escape_quote(module_name)}")
219
+ io.puts %("#{escape_quote(module_name)}" #{build_attributes(label: module_name, id: @metadata_store.issue_modules_id(module_names))})
222
220
 
223
221
  next_proc&.call
224
222
  end
@@ -260,7 +258,7 @@ module DiverDown
260
258
  minlen: MODULE_MINLEN
261
259
  )
262
260
 
263
- io.write(%("#{from_modules[-1]}" -> "#{to_modules[-1]}"))
261
+ io.write(%("#{escape_quote(from_modules[-1])}" -> "#{escape_quote(to_modules[-1])}"))
264
262
  io.write(%( #{build_attributes(**attributes)}), indent: false) unless attributes.empty?
265
263
  io.write("\n")
266
264
  end
@@ -268,13 +266,64 @@ module DiverDown
268
266
  end
269
267
  end
270
268
 
271
- def insert_source(source)
272
- if module_store.get(source.source_name).empty?
273
- io.puts %("#{source.source_name}" #{build_attributes(label: source.source_name, id: @metadata_store.issue_source_id(source))})
274
- else
275
- insert_modules(source)
269
+ def render_sources
270
+ by_modules = definition.sources.group_by do |source|
271
+ module_store.get(source.source_name)
272
+ end
273
+
274
+ # Remove duplicated prefix modules
275
+ # from [["A"], ["A", "B"]] to [["A", "B"]]
276
+ uniq_modules = by_modules.keys.uniq
277
+ uniq_modules = uniq_modules.reject do |modules|
278
+ uniq_modules.any? { _1[0..modules.size - 1] == modules && _1.length > modules.size }
279
+ end
280
+
281
+ uniq_modules.each do |full_modules|
282
+ # Render module and source
283
+ if full_modules.empty?
284
+ sources = by_modules[full_modules].sort_by(&:source_name)
285
+
286
+ sources.each do |source|
287
+ insert_source(source)
288
+ end
289
+ else
290
+ buf = swap_io do
291
+ indexes = (0..(full_modules.length - 1)).to_a
292
+
293
+ chain_yield(indexes) do |index, next_proc|
294
+ module_names = full_modules[0..index]
295
+ module_name = module_names[-1]
296
+
297
+ io.puts %(subgraph "#{escape_quote(module_label(module_names))}" {)
298
+ io.indented do
299
+ io.puts %(id="#{@metadata_store.issue_modules_id(module_names)}")
300
+ io.puts %(label="#{escape_quote(module_name)}")
301
+
302
+ sources = (by_modules[module_names] || []).sort_by(&:source_name)
303
+ sources.each do |source|
304
+ insert_source(source)
305
+ end
306
+
307
+ next_proc&.call
308
+ end
309
+ io.puts '}'
310
+ end
311
+ end
312
+
313
+ io.write buf.string
314
+ end
276
315
  end
277
316
 
317
+ definition.sources.sort_by(&:source_name).each do |source|
318
+ insert_dependencies(source)
319
+ end
320
+ end
321
+
322
+ def insert_source(source)
323
+ io.puts %("#{escape_quote(source.source_name)}" #{build_attributes(label: source.source_name, id: @metadata_store.issue_source_id(source))})
324
+ end
325
+
326
+ def insert_dependencies(source)
278
327
  source.dependencies.each do
279
328
  attributes = {}
280
329
  ltail = module_label(*module_store.get(source.source_name))
@@ -307,40 +356,12 @@ module DiverDown
307
356
  )
308
357
  end
309
358
 
310
- io.write(%("#{source.source_name}" -> "#{_1.source_name}"))
359
+ io.write(%("#{escape_quote(source.source_name)}" -> "#{escape_quote(_1.source_name)}"))
311
360
  io.write(%( #{build_attributes(**attributes)}), indent: false) unless attributes.empty?
312
361
  io.write("\n")
313
362
  end
314
363
  end
315
364
 
316
- def insert_modules(source)
317
- buf = swap_io do
318
- all_module_names = module_store.get(source.source_name)
319
- indexes = (0..(all_module_names.length - 1)).to_a
320
-
321
- chain_yield(indexes) do |index, next_proc|
322
- module_names = all_module_names[0..index]
323
- module_name = module_names[-1]
324
-
325
- io.puts %(subgraph "#{module_label(module_names)}" {)
326
- io.indented do
327
- io.puts %(id="#{@metadata_store.issue_modules_id(module_names)}")
328
- io.puts %(label="#{module_name}")
329
-
330
- if next_proc
331
- next_proc.call
332
- else
333
- # last. equals indexes[-1] == index
334
- io.puts %("#{source.source_name}" #{build_attributes(label: source.source_name, id: @metadata_store.issue_source_id(source))})
335
- end
336
- end
337
- io.puts '}'
338
- end
339
- end
340
-
341
- io.write buf.string
342
- end
343
-
344
365
  def chain_yield(values, &block)
345
366
  *head, tail = values
346
367
 
@@ -363,7 +384,7 @@ module DiverDown
363
384
  attrs = attrs.reject { _2.nil? || _2 == '' }
364
385
  return if attrs.empty?
365
386
 
366
- attrs_str = attrs.map { %(#{_1}="#{_2}") }.join(ATTRIBUTE_DELIMITER)
387
+ attrs_str = attrs.map { %(#{_1}="#{escape_quote(_2)}") }.join(ATTRIBUTE_DELIMITER)
367
388
 
368
389
  if _wrap
369
390
  "#{_wrap[0]}#{attrs_str}#{_wrap[1]}"
@@ -394,6 +415,10 @@ module DiverDown
394
415
 
395
416
  "cluster_#{modules.join(MODULE_DELIMITER)}"
396
417
  end
418
+
419
+ def escape_quote(string)
420
+ string.to_s.gsub(/"/, '\"')
421
+ end
397
422
  end
398
423
  end
399
424
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: diver_down
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.alpha5
4
+ version: 0.0.1.alpha7
5
5
  platform: ruby
6
6
  authors:
7
7
  - alpaca-tc
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-05-09 00:00:00.000000000 Z
11
+ date: 2024-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport