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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 44b324c969e0eee61a4e445debbb87b34d55a12995f1c72a4dc52d2f86807d68
4
- data.tar.gz: 3caefc54af9dadbcd83fc9dc5cd903f04a1acd9034043bf90424e83f888314ce
3
+ metadata.gz: 77adb613fe39a632f031c03043e04a4d063544bc52981be78b4a7940ed72aa9a
4
+ data.tar.gz: 187db445f834508dd9980ed23b53c847a9be21bcf277f7dc05fcec1a5c80db13
5
5
  SHA512:
6
- metadata.gz: 987f4cd19880122491628b747a516f38f4e1a3124cdd54ecbd200070b294a0227e7172ca6aa3c07cc21c455430ebe4c3b3ff7dad94e5566f7e784704ee501c5b
7
- data.tar.gz: c28ac4b38fdb99fa83e05b14992e935007ce0d7dfa760a87703fba4ad83e44b7ea1c289db222fcfcd2aac0f3b9a1c7de0961188b79d3d095f5f26e2a76989d6b
6
+ metadata.gz: 6014c3b504f50736f97fa2c47089a95b17021f08ce60b9510ccbab0f3c224804be9b52cc381255ad6ef5de2470d1bb66f5206fe3db620a6161e24a0cfcdfe525
7
+ data.tar.gz: 14c5773be07183a884c25c4fe17d3d2f5a3eb4d607790a68f826db3699a3fa068c6b42f95de62a8cc487cc736b9839928cb2f5b534a5924254be7ab96d7b7ab4
data/.editorconfig ADDED
@@ -0,0 +1,3 @@
1
+ [*]
2
+ indent_size = 2
3
+ indent_style = space
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
@@ -5,5 +5,5 @@ require 'bundler/setup'
5
5
  require 'simple-hd-graph'
6
6
 
7
7
  Version = SimpleHdGraph::VERSION
8
- cmd = SimpleHdGraph::Command.new(ARGV)
9
- cmd.run
8
+ cmd = SimpleHdGraph::Command.new
9
+ cmd.run(ARGV)
@@ -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
- def initialize(argv)
6
- @argv = argv.dup
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
- def run
10
- opts.parse(@argv)
11
- if @file
12
- nodes = Parser.new.parse(Reader.new.read_file(@file))
13
- renderer = Renderer::PlantUML::Context.new
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
- puts nodes.map { |node|
16
- renderer.render(node)
17
- }.join
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
- @file = value
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
@@ -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(':@required_fields').size > 0
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
@@ -14,6 +14,8 @@ module SimpleHdGraph
14
14
  contexts = []
15
15
 
16
16
  YAML.load_stream(document) do |node|
17
+ next unless node
18
+
17
19
  context = nil
18
20
  resources = []
19
21
 
@@ -1,3 +1,3 @@
1
1
  module SimpleHdGraph
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
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.1.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-15 00:00:00.000000000 Z
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