sanctuary-planter 0.1.2 → 0.1.3
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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/sanctuary/planter/cli.rb +14 -9
- data/lib/sanctuary/planter/generator.rb +21 -0
- data/lib/sanctuary/planter/parser.rb +48 -0
- data/lib/sanctuary/planter/plant.rb +13 -0
- data/lib/sanctuary/planter/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 227730cb03cbabaa8095a3eed4d75491de5bacb39d252dbcffd09dc144bc52bc
|
|
4
|
+
data.tar.gz: fb61c821b94bb9467e435ade8aa83ec23e259dd42459f292e97028b256472864
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d74f9290c917e3315bb365034d3f6a4f1ec36d99f0ced8fee83abe8171d9fcaeccb4aa20dc286107b862ce1766598a5d2df2c32f07ea2111a4bc7fb1d1f37cd5
|
|
7
|
+
data.tar.gz: 6ed2984b10433b65b6c6237ac59f1a24b4319ab5039211b2ca11e9c3809e1a3b6a09b22f0238ec4dba45ab9e2de736b39bac46e6427ca51ec96d05125b75adf6
|
data/Gemfile.lock
CHANGED
|
@@ -1,20 +1,25 @@
|
|
|
1
1
|
require "sanctuary"
|
|
2
|
+
require "sanctuary/planter/parser"
|
|
3
|
+
require "sanctuary/planter/generator"
|
|
2
4
|
|
|
3
5
|
module Sanctuary
|
|
4
6
|
module Planter
|
|
5
7
|
class CLI
|
|
6
8
|
def self.start
|
|
7
9
|
if ARGV.include?("-i")
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
end
|
|
10
|
+
classes_array = Sanctuary::Planter::Parser.parse_plant_uml(ARGV[1])
|
|
11
|
+
plant_array = Sanctuary::Planter::Parser.generate_plant_data_objects(classes_array)
|
|
12
|
+
plant_array.each do |plant|
|
|
13
|
+
Sanctuary::Planter::Generator.generate_file_from_plant(plant)
|
|
14
|
+
end
|
|
16
15
|
else
|
|
17
|
-
|
|
16
|
+
system("vim", "tmp.puml")
|
|
17
|
+
classes_array = Sanctuary::Planter::Parser.parse_plant_uml("./tmp.puml")
|
|
18
|
+
plant_array = Sanctuary::Planter::Parser.generate_plant_data_objects(classes_array)
|
|
19
|
+
plant_array.each do |plant|
|
|
20
|
+
Sanctuary::Planter::Generator.generate_file_from_plant(plant)
|
|
21
|
+
end
|
|
22
|
+
File.delete("./tmp.puml") if File.exists? ("./tmp.puml")
|
|
18
23
|
end
|
|
19
24
|
end
|
|
20
25
|
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require "sanctuary"
|
|
2
|
+
|
|
3
|
+
module Sanctuary
|
|
4
|
+
module Planter
|
|
5
|
+
module Generator
|
|
6
|
+
def self.generate_file_from_plant(plant)
|
|
7
|
+
home_dir = Sanctuary::HOME_DIR
|
|
8
|
+
template_file = IO.read(home_dir + "/" + plant.plant_template)
|
|
9
|
+
template = ERB.new(template_file, nil, '-%<>')
|
|
10
|
+
local_binding = binding
|
|
11
|
+
local_binding.local_variable_set(:name, plant.name)
|
|
12
|
+
local_binding.local_variable_set(:fields, plant.fields)
|
|
13
|
+
local_binding.local_variable_set(:methods, plant.methods)
|
|
14
|
+
puts "Generated #{plant.name}"
|
|
15
|
+
File.open(plant.name + "." + plant.plant_template.split("/").last.split(".")[1], "w") do |f|
|
|
16
|
+
f.write(template.result(local_binding))
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
require "sanctuary/planter/plant"
|
|
2
|
+
|
|
3
|
+
module Sanctuary
|
|
4
|
+
module Planter
|
|
5
|
+
module Parser
|
|
6
|
+
def self.parse_plant_uml(path)
|
|
7
|
+
classes = []
|
|
8
|
+
File.open(path) do |file|
|
|
9
|
+
reading = false
|
|
10
|
+
lines_read = ""
|
|
11
|
+
file.each do |line|
|
|
12
|
+
if line.include?("TYPE")
|
|
13
|
+
reading = true
|
|
14
|
+
end
|
|
15
|
+
if reading
|
|
16
|
+
lines_read << line
|
|
17
|
+
end
|
|
18
|
+
if line.include?("}")
|
|
19
|
+
reading = false
|
|
20
|
+
classes << lines_read.split("\n")
|
|
21
|
+
lines_read = ""
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
classes
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def self.generate_plant_data_objects(classes_array)
|
|
30
|
+
classes_array.map do |klass|
|
|
31
|
+
fields = []
|
|
32
|
+
methods = []
|
|
33
|
+
plant_template = klass[0].split(":")[1].chomp
|
|
34
|
+
name = klass[1].split("class")[1].split(" ")[0].chomp
|
|
35
|
+
klass[2..(klass.length - 2)].each do |line|
|
|
36
|
+
if line.include?("()")
|
|
37
|
+
methods << line.strip
|
|
38
|
+
else
|
|
39
|
+
fields << line.strip
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
Sanctuary::Planter::Plant.new(name, fields, methods, plant_template)
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module Sanctuary
|
|
2
|
+
module Planter
|
|
3
|
+
class Plant
|
|
4
|
+
attr_accessor :name, :fields, :methods, :plant_template
|
|
5
|
+
def initialize(name, fields, methods, plant_template)
|
|
6
|
+
@name = name
|
|
7
|
+
@fields = fields
|
|
8
|
+
@methods = methods
|
|
9
|
+
@plant_template = plant_template
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: sanctuary-planter
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Kevin-Kawai
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2019-
|
|
11
|
+
date: 2019-08-03 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: sanctuary
|
|
@@ -101,6 +101,9 @@ files:
|
|
|
101
101
|
- bin/setup
|
|
102
102
|
- lib/sanctuary/planter.rb
|
|
103
103
|
- lib/sanctuary/planter/cli.rb
|
|
104
|
+
- lib/sanctuary/planter/generator.rb
|
|
105
|
+
- lib/sanctuary/planter/parser.rb
|
|
106
|
+
- lib/sanctuary/planter/plant.rb
|
|
104
107
|
- lib/sanctuary/planter/version.rb
|
|
105
108
|
- sanctuary-planter.gemspec
|
|
106
109
|
homepage: https://www.github.com
|