simple-hd-graph 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.editorconfig +3 -0
- data/README.md +43 -0
- data/exe/simple-hd-graph +2 -2
- data/lib/simple-hd-graph/command.rb +59 -12
- data/lib/simple-hd-graph/node.rb +1 -1
- data/lib/simple-hd-graph/parser.rb +2 -0
- data/lib/simple-hd-graph/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 77adb613fe39a632f031c03043e04a4d063544bc52981be78b4a7940ed72aa9a
|
4
|
+
data.tar.gz: 187db445f834508dd9980ed23b53c847a9be21bcf277f7dc05fcec1a5c80db13
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6014c3b504f50736f97fa2c47089a95b17021f08ce60b9510ccbab0f3c224804be9b52cc381255ad6ef5de2470d1bb66f5206fe3db620a6161e24a0cfcdfe525
|
7
|
+
data.tar.gz: 14c5773be07183a884c25c4fe17d3d2f5a3eb4d607790a68f826db3699a3fa068c6b42f95de62a8cc487cc736b9839928cb2f5b534a5924254be7ab96d7b7ab4
|
data/.editorconfig
ADDED
data/README.md
CHANGED
@@ -22,6 +22,49 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
$ simple-hd-graph -f FILE
|
24
24
|
|
25
|
+
## Example
|
26
|
+
|
27
|
+
input
|
28
|
+
|
29
|
+
```yaml
|
30
|
+
id: example1
|
31
|
+
resources:
|
32
|
+
web:
|
33
|
+
hosting: Heroku
|
34
|
+
runtime: Ruby 2.5
|
35
|
+
has:
|
36
|
+
- admin
|
37
|
+
- storage
|
38
|
+
admin:
|
39
|
+
hosting: Google Spreadsheet
|
40
|
+
runtime: Google Apps Script
|
41
|
+
storage:
|
42
|
+
hosting: AWS S3
|
43
|
+
region: ap-north-east1
|
44
|
+
```
|
45
|
+
|
46
|
+
output
|
47
|
+
|
48
|
+
```plantuml
|
49
|
+
rectangle "example1" as example1 {
|
50
|
+
object "web" as example1Web {
|
51
|
+
hosting: Heroku
|
52
|
+
runtime: Ruby 2.5
|
53
|
+
}
|
54
|
+
object "admin" as example1Admin {
|
55
|
+
hosting: Google Spreadsheet
|
56
|
+
runtime: Google Apps Script
|
57
|
+
}
|
58
|
+
object "storage" as example1Storage {
|
59
|
+
hosting: AWS S3
|
60
|
+
region: ap-north-east1
|
61
|
+
}
|
62
|
+
|
63
|
+
example1Web -d-|> example1Admin
|
64
|
+
example1Web -d-|> example1Storage
|
65
|
+
}
|
66
|
+
```
|
67
|
+
|
25
68
|
## Development
|
26
69
|
|
27
70
|
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.
|
data/exe/simple-hd-graph
CHANGED
@@ -1,31 +1,78 @@
|
|
1
1
|
require 'optparse'
|
2
2
|
|
3
3
|
module SimpleHdGraph
|
4
|
+
class Error < StandardError; end
|
5
|
+
class FileNotExist < Error; end
|
6
|
+
class DirectoryNotExist < Error; end
|
7
|
+
|
4
8
|
class Command
|
5
|
-
|
6
|
-
|
9
|
+
#
|
10
|
+
# @param parser [Parser]
|
11
|
+
# @param reader [Reader]
|
12
|
+
# @param renderer [Renderer]
|
13
|
+
#
|
14
|
+
def initialize(parser: Parser.new, reader: Reader.new, renderer: Renderer::PlantUML::Context.new)
|
15
|
+
@parser = parser
|
16
|
+
@reader = reader
|
17
|
+
@renderer = renderer
|
7
18
|
end
|
19
|
+
attr_reader :parser, :reader, :renderer
|
8
20
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
21
|
+
#
|
22
|
+
# @param argv [Array]
|
23
|
+
#
|
24
|
+
def run(argv)
|
25
|
+
parse(argv)
|
26
|
+
if @file || @dir
|
27
|
+
start
|
28
|
+
end
|
29
|
+
end
|
14
30
|
|
15
|
-
|
16
|
-
|
17
|
-
|
31
|
+
#
|
32
|
+
# @param argv [Array]
|
33
|
+
#
|
34
|
+
def parse(argv)
|
35
|
+
opts.parse(argv)
|
36
|
+
end
|
37
|
+
|
38
|
+
#
|
39
|
+
# @return [String]
|
40
|
+
#
|
41
|
+
def stream
|
42
|
+
if (@dir)
|
43
|
+
reader.read_dir(@dir)
|
44
|
+
else
|
45
|
+
reader.read_file(@file)
|
18
46
|
end
|
19
47
|
end
|
20
48
|
|
49
|
+
def start
|
50
|
+
nodes = parser.parse(stream)
|
51
|
+
|
52
|
+
puts nodes.map { |node|
|
53
|
+
renderer.render(node)
|
54
|
+
}.join
|
55
|
+
end
|
56
|
+
|
21
57
|
#
|
22
58
|
# @return [OptionParser]
|
23
59
|
#
|
24
|
-
# :reek:NestedIterators
|
60
|
+
# :reek:NestedIterators, :reek:DuplicateMethodCall
|
25
61
|
def opts
|
26
62
|
OptionParser.new do |opt|
|
63
|
+
opt.on('-d DIR', '--dir', 'dirname') { |value|
|
64
|
+
if File.exist?(value) && File.directory?(value)
|
65
|
+
@dir = value
|
66
|
+
else
|
67
|
+
raise DirectoryNotExist, value
|
68
|
+
end
|
69
|
+
}
|
27
70
|
opt.on('-f FILE', '--file', 'filename') { |value|
|
28
|
-
|
71
|
+
if File.exist?(value) && File.file?(value)
|
72
|
+
@file = value
|
73
|
+
else
|
74
|
+
raise FileNotExist, value
|
75
|
+
end
|
29
76
|
}
|
30
77
|
end
|
31
78
|
end
|
data/lib/simple-hd-graph/node.rb
CHANGED
@@ -24,7 +24,7 @@ module SimpleHdGraph
|
|
24
24
|
def load(struct)
|
25
25
|
klass = self.class
|
26
26
|
|
27
|
-
required_fields = if klass.instance_variables.grep(
|
27
|
+
required_fields = if klass.instance_variables.grep(/@required_fields/).size > 0
|
28
28
|
klass.instance_variable_get('@required_fields')
|
29
29
|
else
|
30
30
|
nil
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple-hd-graph
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- wtnabe
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-04-
|
11
|
+
date: 2021-04-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-inflector
|
@@ -117,6 +117,7 @@ executables:
|
|
117
117
|
extensions: []
|
118
118
|
extra_rdoc_files: []
|
119
119
|
files:
|
120
|
+
- ".editorconfig"
|
120
121
|
- ".gitignore"
|
121
122
|
- ".travis.yml"
|
122
123
|
- Gemfile
|