simple-hd-graph 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 77adb613fe39a632f031c03043e04a4d063544bc52981be78b4a7940ed72aa9a
4
- data.tar.gz: 187db445f834508dd9980ed23b53c847a9be21bcf277f7dc05fcec1a5c80db13
3
+ metadata.gz: 8c9b0d3ded87feb7413df4ddeba6059e109be00644737ded9a4e814f8e9a1e67
4
+ data.tar.gz: 9c677cc4cd05e216464afe2b3c04ba8b321a595dedb5932292bfd5ec4dbd7c90
5
5
  SHA512:
6
- metadata.gz: 6014c3b504f50736f97fa2c47089a95b17021f08ce60b9510ccbab0f3c224804be9b52cc381255ad6ef5de2470d1bb66f5206fe3db620a6161e24a0cfcdfe525
7
- data.tar.gz: 14c5773be07183a884c25c4fe17d3d2f5a3eb4d607790a68f826db3699a3fa068c6b42f95de62a8cc487cc736b9839928cb2f5b534a5924254be7ab96d7b7ab4
6
+ metadata.gz: 99df519c7c3e8927c09ed17e6b6a8dd9d0533cd7885ff59592d2da9f614ea2c2bff15d4473095f108b19bd1b045b07de3013d2a3a94b1025af878280bce6d159
7
+ data.tar.gz: 81d0c1f6c5359f88cca05d4f3beaeb6c55ce73a19cbd966c3a8086fc8553e690b77a8ad96af359a186940958b2733f187067f8df58351cb631db2738bc3f314b
data/README.md CHANGED
@@ -22,9 +22,42 @@ Or install it yourself as:
22
22
 
23
23
  $ simple-hd-graph -f FILE
24
24
 
25
+ or
26
+
27
+ $ simple-hd-graph -d DIR
28
+
29
+ ## Format
30
+
31
+ SimpleHdGraph was designed primarily to describe systems, its constituent resources, and their dependencies.
32
+
33
+ The two components are as follows:
34
+
35
+ * Context
36
+ * Resource
37
+
38
+ A single YAML document corresponds to a single context as below:
39
+
40
+ <pre>
41
+ <b>id</b>: name1
42
+ <b>resources</b>:
43
+ resource1:
44
+ note: memo
45
+ <b>has</b>: resource2
46
+ resource2:
47
+ note: very important
48
+ <b>depends</b>:
49
+ - name2
50
+ </pre>
51
+
52
+ features:
53
+
54
+ * Context can contain mutiple Resources
55
+ * Resource can use the `has` keyword to indicate that it owns other Resources
56
+ * Context can use the `depends` keyword to indicate its dependency on other Contexts
57
+
25
58
  ## Example
26
59
 
27
- input
60
+ input ( streams )
28
61
 
29
62
  ```yaml
30
63
  id: example1
@@ -41,6 +74,14 @@ resources:
41
74
  storage:
42
75
  hosting: AWS S3
43
76
  region: ap-north-east1
77
+ ---
78
+ id: example 2
79
+ resources:
80
+ web:
81
+ hosting: Google AppEngines
82
+ runtime: Ruby 2.6
83
+ depends:
84
+ - example1
44
85
  ```
45
86
 
46
87
  output
@@ -63,8 +104,19 @@ rectangle "example1" as example1 {
63
104
  example1Web -d-|> example1Admin
64
105
  example1Web -d-|> example1Storage
65
106
  }
107
+ rectangle "example 2" as example2 {
108
+ object "web" as example2Web {
109
+ hosting: Google AppEngines
110
+ runtime: Ruby 2.6
111
+ }
112
+ }
113
+ example2 -|> example1
66
114
  ```
67
115
 
116
+ after plantuml converted
117
+
118
+ ![example output converted by plantuml](example.png)
119
+
68
120
  ## Development
69
121
 
70
122
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -73,4 +125,4 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
73
125
 
74
126
  ## Contributing
75
127
 
76
- Bug reports and pull requests are welcome on GitHub at https://github.com/wtnabe/graph.
128
+ Bug reports and pull requests are welcome on GitHub at https://github.com/wtnabe/simple-hd-graph.
data/example.png ADDED
Binary file
@@ -2,7 +2,7 @@ module SimpleHdGraph
2
2
  class ContextNode < Node
3
3
  required :id
4
4
 
5
- attr_reader :resources, :relations
5
+ attr_reader :resources, :relations, :depends # Array
6
6
 
7
7
  #
8
8
  # @return [String]
@@ -20,6 +20,9 @@ module SimpleHdGraph
20
20
  id
21
21
  end
22
22
 
23
+ #
24
+ # @param resource [ResourceNode]
25
+ #
23
26
  def <<(resource)
24
27
  @resources ||= []
25
28
  @resource_dict ||= {}
@@ -28,8 +31,15 @@ module SimpleHdGraph
28
31
  end
29
32
 
30
33
  #
31
- # :reek:NestedIterators
34
+ # @param depends [Array]
35
+ #
36
+ def set_depends(depends)
37
+ @depends = depends
38
+ end
39
+
40
+ # :reek:NestedIterators, :reek:TooManyStatements
32
41
  def refill_relation
42
+ @resource ||= []
33
43
  @relations ||= []
34
44
  @resources.each { |resource|
35
45
  dependencies = resource.has
@@ -6,6 +6,10 @@ module SimpleHdGraph
6
6
  #
7
7
  # :reek:InstanceVaariableAssumption
8
8
  class Parser
9
+ KEYWORD_ID ||= 'id'.freeze
10
+ KEYWORD_RESOURCES ||= 'resources'.freeze
11
+ KEYWORD_DEPENDS ||= 'depends'.freeze
12
+
9
13
  #
10
14
  # @param document [String]
11
15
  #
@@ -17,29 +21,50 @@ module SimpleHdGraph
17
21
  next unless node
18
22
 
19
23
  context = nil
20
- resources = []
24
+ resources = nil
25
+ depends = nil
21
26
 
22
- # :reek:NestedIterators
23
27
  node.each_pair { |key, value|
24
- if key == 'id'
28
+ case key
29
+ when KEYWORD_ID
25
30
  context = ContextNode.new
26
31
  context.load({ id: value })
27
- elsif reserved_keywords.include?(key)
28
- elsif key == 'resources'
32
+ when KEYWORD_DEPENDS
33
+ depends = value
34
+ when KEYWORD_RESOURCES
29
35
  resources = value
30
36
  end
31
37
  }
32
38
 
33
- resources.each { |key, resource|
34
- rn = ResourceNode.new
35
- rn.load_with_context({ id: context.id }, { key => resource })
36
- context << rn
37
- }
39
+ pack_depends_into_context(depends, context) if depends
40
+ pack_resources_into_context(resources, context) if resources
41
+
38
42
  contexts << context
39
43
  end
40
44
  refill_relation(contexts)
45
+ refill_depends(contexts)
41
46
 
42
- contexts
47
+ contexts.map { |context| context.freeze }.freeze
48
+ end
49
+
50
+ #
51
+ # @param depends [Array]
52
+ # @param context [ContextNode]
53
+ #
54
+ def pack_depends_into_context(depends, context)
55
+ context.set_depends depends
56
+ end
57
+
58
+ #
59
+ # @param resources [Array]
60
+ # @param context [ContextNode]
61
+ #
62
+ def pack_resources_into_context(resources, context)
63
+ resources.each { |key, resource|
64
+ rn = ResourceNode.new
65
+ rn.load_with_context({ id: context.id }, { key => resource })
66
+ context << rn
67
+ }
43
68
  end
44
69
 
45
70
  #
@@ -52,10 +77,19 @@ module SimpleHdGraph
52
77
  end
53
78
 
54
79
  #
55
- # @return [Array]
80
+ # @param context [Array]
56
81
  #
57
- def reserved_keywords
58
- [:depends]
82
+ def refill_depends(contexts)
83
+ contexts.map { |context|
84
+ if context.depends
85
+ regularized = context.depends.map { |dependee|
86
+ { context.id => dependee }
87
+ }
88
+ context.set_depends regularized
89
+ else
90
+ context.set_depends []
91
+ end
92
+ }
59
93
  end
60
94
  end
61
95
  end
@@ -9,19 +9,23 @@ module SimpleHdGraph
9
9
  #
10
10
  # @param node [ContextNode]
11
11
  #
12
- # :reek:FeatureEnvy
12
+ # :reek:FeatureEnvy, :reek:DuplicateMethodCall
13
13
  def render(node)
14
14
  resources = node.resources.map { |resource|
15
15
  indent_resource(resource)
16
- }.join
16
+ }.join if node.resources.size > 0
17
17
  relations = node.relations.map { |relation|
18
18
  render_relation(relation)
19
- }.join("\n")
20
- <<EOD
19
+ }.join("\n") if node.relations.size > 0
20
+ depends = node.depends.map { |depending|
21
+ render_depends(depending)
22
+ }.join("\n") if node.depends.size > 0
23
+ (<<-EOD).gsub(/^$\n/, '')
21
24
  rectangle \"#{node.alias}\" as #{node.id} {
22
25
  #{resources}
23
- #{relations if relations.size > 0}
26
+ #{relations}
24
27
  }
28
+ #{depends}
25
29
  EOD
26
30
  end
27
31
 
@@ -44,6 +48,16 @@ EOD
44
48
  depender, dependee = relation.to_a.first
45
49
  " #{depender} -d-|> #{dependee}"
46
50
  end
51
+
52
+ #
53
+ # @param depending [Hash]
54
+ # @return [String]
55
+ #
56
+ # :reek:UtilityFunction
57
+ def render_depends(depending)
58
+ depender, dependee = depending.to_a.first
59
+ "#{depender} -|> #{dependee}"
60
+ end
47
61
  end
48
62
  end
49
63
  end
@@ -1,3 +1,3 @@
1
1
  module SimpleHdGraph
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple-hd-graph
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - wtnabe
@@ -126,6 +126,7 @@ files:
126
126
  - Rakefile
127
127
  - bin/console
128
128
  - bin/setup
129
+ - example.png
129
130
  - exe/simple-hd-graph
130
131
  - lib/simple-hd-graph.rb
131
132
  - lib/simple-hd-graph/command.rb