diver_down 0.0.1.alpha5 → 0.0.1.alpha6

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: 7d4a5bb567f1141aaa13b3d6aaf7e4201b005988a072cfd5c4de2e11a180c480
4
+ data.tar.gz: 5cf5455488b8944830f2f25fb7f26a1b4d21ed2d42ee1c2ea755138ba3aa40e3
5
5
  SHA512:
6
- metadata.gz: 350384f94a2c60506fffe52d43bdd705bf048cf6d62dfdd60f3d315fe89e9647896f1b9fc6491dc5bfeccd475c970580bd1ee4599e843a79e8bfd17d4d1f0764
7
- data.tar.gz: e16ffe92d2df53c258e7fc4a295411f7f35611334af421d9e78b7fcc1b9e7b77190cdf568ca3fd0fa82a0340cd04175e2bb631cdfee3467bfdc31eb6f687e7c8
6
+ metadata.gz: 79b39d0ecc4569ce41d26c24ae03d903c431a7cdc55c9c9fecbcbbfadc807edbdcab3c34481fde3b6d728791b780951ef1923afb37414f6403a3daa415537d73
7
+ data.tar.gz: '0800be880d27a2c61c8e7153bbea2c02ab8573d347a5b5cccd9325549e7284f2d8c4316b3fb794c9fa0c42ee47e9fa9d7df9d9a24efe4d106ba5d767c2d3c0a3'
@@ -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.alpha6'
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,62 @@ 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 }
276
279
  end
277
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
+ insert_dependencies(source)
289
+ end
290
+ else
291
+ buf = swap_io do
292
+ indexes = (0..(full_modules.length - 1)).to_a
293
+
294
+ chain_yield(indexes) do |index, next_proc|
295
+ module_names = full_modules[0..index]
296
+ module_name = module_names[-1]
297
+
298
+ io.puts %(subgraph "#{escape_quote(module_label(module_names))}" {)
299
+ io.indented do
300
+ io.puts %(id="#{@metadata_store.issue_modules_id(module_names)}")
301
+ io.puts %(label="#{escape_quote(module_name)}")
302
+
303
+ sources = (by_modules[module_names] || []).sort_by(&:source_name)
304
+ sources.each do |source|
305
+ insert_source(source)
306
+ insert_dependencies(source)
307
+ end
308
+
309
+ next_proc&.call
310
+ end
311
+ io.puts '}'
312
+ end
313
+ end
314
+
315
+ io.write buf.string
316
+ end
317
+ end
318
+ end
319
+
320
+ def insert_source(source)
321
+ io.puts %("#{escape_quote(source.source_name)}" #{build_attributes(label: source.source_name, id: @metadata_store.issue_source_id(source))})
322
+ end
323
+
324
+ def insert_dependencies(source)
278
325
  source.dependencies.each do
279
326
  attributes = {}
280
327
  ltail = module_label(*module_store.get(source.source_name))
@@ -307,40 +354,12 @@ module DiverDown
307
354
  )
308
355
  end
309
356
 
310
- io.write(%("#{source.source_name}" -> "#{_1.source_name}"))
357
+ io.write(%("#{escape_quote(source.source_name)}" -> "#{escape_quote(_1.source_name)}"))
311
358
  io.write(%( #{build_attributes(**attributes)}), indent: false) unless attributes.empty?
312
359
  io.write("\n")
313
360
  end
314
361
  end
315
362
 
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
363
  def chain_yield(values, &block)
345
364
  *head, tail = values
346
365
 
@@ -363,7 +382,7 @@ module DiverDown
363
382
  attrs = attrs.reject { _2.nil? || _2 == '' }
364
383
  return if attrs.empty?
365
384
 
366
- attrs_str = attrs.map { %(#{_1}="#{_2}") }.join(ATTRIBUTE_DELIMITER)
385
+ attrs_str = attrs.map { %(#{_1}="#{escape_quote(_2)}") }.join(ATTRIBUTE_DELIMITER)
367
386
 
368
387
  if _wrap
369
388
  "#{_wrap[0]}#{attrs_str}#{_wrap[1]}"
@@ -394,6 +413,10 @@ module DiverDown
394
413
 
395
414
  "cluster_#{modules.join(MODULE_DELIMITER)}"
396
415
  end
416
+
417
+ def escape_quote(string)
418
+ string.to_s.gsub(/"/, '\"')
419
+ end
397
420
  end
398
421
  end
399
422
  end
metadata CHANGED
@@ -1,7 +1,7 @@
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.alpha6
5
5
  platform: ruby
6
6
  authors:
7
7
  - alpaca-tc