yamldag 0.0.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 +7 -0
- data/bin/yamldag +14 -0
- data/lib/yamldag.rb +62 -0
- metadata +45 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 68cbc3f6acc79db49e8dd59e6cc70108401e7e51f1f867e944a12985df49f5d8
|
4
|
+
data.tar.gz: 468ae9718a64375194369a8ef4ad42219de651254a91bfc7704ba317d23ca05b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 463c8acfa113025fa1709c00828cc66fe5fc69102c3fed9f18339b09dcf1dd26d20e1470a75573065e1ba09929ef391e75e002350bbdc5c45c9a83738059aaa8
|
7
|
+
data.tar.gz: ef236da412f44b190a1360fb993f84487bdbe4e802b669462262ff4cd0828bbf20721d708b633f26fe829fd77e212713d7fbf36dafc5b84ae2dcb68c292db128
|
data/bin/yamldag
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'yamldag'
|
3
|
+
|
4
|
+
if ARGV.length > 0
|
5
|
+
yamlfile = ARGV.first
|
6
|
+
if !File.exist?(yamlfile)
|
7
|
+
puts "#{yamlfile} not found"
|
8
|
+
elsif
|
9
|
+
object = YamlDag.new(ARGV.first)
|
10
|
+
object.build
|
11
|
+
end
|
12
|
+
elsif
|
13
|
+
puts "Just need to pass in a yaml file path 'yaml_dagv path/to/xx.yaml'"
|
14
|
+
end
|
data/lib/yamldag.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'plexus'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
class YamlDag
|
5
|
+
include Plexus
|
6
|
+
|
7
|
+
def initialize(filepath)
|
8
|
+
@dag = DirectedGraph.new # alias of Digraph
|
9
|
+
@filepath = filepath
|
10
|
+
end
|
11
|
+
|
12
|
+
def build
|
13
|
+
add_vertices_and_edges
|
14
|
+
# is cycle graph ?
|
15
|
+
if @dag.cyclic?
|
16
|
+
# puts "strong_components ==> #{@dag.strong_components}"
|
17
|
+
@nodes = @dag.strong_components.select{|a| a.length > 1}
|
18
|
+
@nodes.each do | ns |
|
19
|
+
puts "<--------------cycle------------------>"
|
20
|
+
puts "#{ns.reverse.join('=>')}=>#{ns.reverse.first}"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
visualize
|
24
|
+
end
|
25
|
+
|
26
|
+
def vertices
|
27
|
+
puts "Vertices #{@dag.vertices}"
|
28
|
+
end
|
29
|
+
|
30
|
+
def ancestors(task)
|
31
|
+
dag.ancestors(task)
|
32
|
+
end
|
33
|
+
|
34
|
+
def root(task)
|
35
|
+
ancestors(task).last
|
36
|
+
end
|
37
|
+
|
38
|
+
def visualize
|
39
|
+
filename = dag.write_to_graphic_file and puts "Created #{filename}"
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
attr_reader :dag, :filepath
|
45
|
+
|
46
|
+
def add_vertices_and_edges(tasks = yml_tasks)
|
47
|
+
tasks.each_pair do |task, child_tasks|
|
48
|
+
next if child_tasks.nil?
|
49
|
+
child_tasks.keys.each do |child|
|
50
|
+
# puts "Adding #{child}"
|
51
|
+
# puts "ancestors #{ancestors(task)}"
|
52
|
+
# puts "root #{root(task)}"
|
53
|
+
dag.add_edge!(task, child)
|
54
|
+
end
|
55
|
+
add_vertices_and_edges(child_tasks)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def yml_tasks
|
60
|
+
@yml_tasks ||= YAML.load_file(filepath)
|
61
|
+
end
|
62
|
+
end
|
metadata
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yamldag
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- bin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-11-23 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: a simple yaml file to generate DAG Graph and visualization
|
14
|
+
email: tangbineml@gmail.com
|
15
|
+
executables:
|
16
|
+
- yamldag
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- bin/yamldag
|
21
|
+
- lib/yamldag.rb
|
22
|
+
homepage: http://rubygems.org/gems/yamldag
|
23
|
+
licenses:
|
24
|
+
- MIT
|
25
|
+
metadata: {}
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
requirements: []
|
41
|
+
rubygems_version: 3.0.3.1
|
42
|
+
signing_key:
|
43
|
+
specification_version: 4
|
44
|
+
summary: a simple yaml file to generate DAG Graph and visualization
|
45
|
+
test_files: []
|