yml2erd 0.9.6 → 0.9.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/yml2erd/cli.rb +5 -0
- data/lib/yml2erd/diagram.rb +8 -3
- data/lib/yml2erd/schema_structure/validator.rb +1 -1
- data/lib/yml2erd/schema_structure.rb +14 -3
- data/lib/yml2erd/version.rb +1 -1
- data/sample.yml +4 -15
- data/yml2erd.gemspec +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 30861d60e3b7ec898d77d7651b115801e4a2411e
|
4
|
+
data.tar.gz: c89d8ff74ca28c0ffd9b8289e5c403acf90867f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0d63ce75a0dc3b53a456ef574c238ac2da6f9369931783e6f9fbaea0126425994f8f92e3212298d486429bf7df100e32316eca3d1310c3336aea5ca03a749493
|
7
|
+
data.tar.gz: 0629c73061313f60e203098664648d8f7117bd5f07c59dba1894d4f5fe978352397a2f2ab2beb0b8203eea7edbe6b34ee9c3e0458d0f5ec5cb6b09d21b543c2b
|
data/lib/yml2erd/cli.rb
CHANGED
@@ -23,7 +23,12 @@ module Yml2erd
|
|
23
23
|
|
24
24
|
private
|
25
25
|
|
26
|
+
def abort_unless_yml(path)
|
27
|
+
abort 'file must be a .yml file' unless path =~ /\.yml$/
|
28
|
+
end
|
29
|
+
|
26
30
|
def load_yml(path)
|
31
|
+
abort_unless_yml(path)
|
27
32
|
abort "#{path} is not found, please check your .yml file path" unless File.exists?(path)
|
28
33
|
yml = YAML.load_file(path)
|
29
34
|
Yml2erd::Parser.parse(yml)
|
data/lib/yml2erd/diagram.rb
CHANGED
@@ -14,8 +14,9 @@ module Yml2erd
|
|
14
14
|
|
15
15
|
table_names.each do |table_name|
|
16
16
|
columns = ''
|
17
|
+
schema_structure.shared_columns.each { |key, value| columns += build_column(key, value) } unless schema_structure.shared_columns.nil?
|
17
18
|
schema_structure.columns(table_name).each do |column|
|
18
|
-
column.each { |key, value| columns +=
|
19
|
+
column.each { |key, value| columns += build_column(key, value) }
|
19
20
|
end
|
20
21
|
|
21
22
|
index = schema_structure.index(table_name)
|
@@ -25,8 +26,8 @@ module Yml2erd
|
|
25
26
|
|
26
27
|
table_names.each do |table_name|
|
27
28
|
if !schema_structure.relation(table_name).nil? && \
|
28
|
-
!schema_structure.
|
29
|
-
schema_structure.
|
29
|
+
!schema_structure.belongs(table_name).nil?
|
30
|
+
schema_structure.belongs(table_name).each do |belongs_to|
|
30
31
|
g.add_edges(belongs_to, table_name)
|
31
32
|
end
|
32
33
|
end
|
@@ -46,6 +47,10 @@ module Yml2erd
|
|
46
47
|
"<{<FONT POINT-SIZE='15'>#{table_name}</FONT> | #{columns}}>"
|
47
48
|
end
|
48
49
|
end
|
50
|
+
|
51
|
+
def build_column(name, type)
|
52
|
+
"#{name}: <FONT color='gray'>#{type}</FONT><BR/>"
|
53
|
+
end
|
49
54
|
end
|
50
55
|
end
|
51
56
|
end
|
@@ -11,14 +11,19 @@ module Yml2erd
|
|
11
11
|
# returns an array which has table_names like bellow
|
12
12
|
# => ["users", "user_auths", "posts", "companies"]
|
13
13
|
def table_names
|
14
|
-
structure_yml.to_a.map { |s| s.first }
|
14
|
+
structure_yml.to_a.map { |s| s.first }.select{ |tn| tn != 'shared_columns' }
|
15
15
|
end
|
16
16
|
|
17
17
|
# returns a hash like below
|
18
|
-
# {
|
18
|
+
# { belongs_to: ['user_auths', 'companies'], has_many: ['posts'] }
|
19
19
|
def relation(table_name)
|
20
20
|
relations = structure_yml[table_name]['relations']
|
21
|
-
|
21
|
+
end
|
22
|
+
|
23
|
+
# returns an array like below
|
24
|
+
# ['user_auths', 'companies']
|
25
|
+
def belongs(table_name)
|
26
|
+
relation(table_name)['belongs_to']
|
22
27
|
end
|
23
28
|
|
24
29
|
def relations
|
@@ -42,5 +47,11 @@ module Yml2erd
|
|
42
47
|
def index(table_name)
|
43
48
|
structure_yml[table_name]['index']
|
44
49
|
end
|
50
|
+
|
51
|
+
# returns a hash like below
|
52
|
+
# => { "id"=>"integer", "created_at"=>"datetime", "updated_at"=>"datetime" }
|
53
|
+
def shared_columns
|
54
|
+
structure_yml['shared_columns']
|
55
|
+
end
|
45
56
|
end
|
46
57
|
end
|
data/lib/yml2erd/version.rb
CHANGED
data/sample.yml
CHANGED
@@ -1,23 +1,21 @@
|
|
1
|
+
shared_columns:
|
2
|
+
id: integer
|
3
|
+
created_at: datetime
|
4
|
+
updated_at: datetime
|
1
5
|
companies:
|
2
6
|
columns:
|
3
|
-
- id: integer
|
4
7
|
- name: string
|
5
8
|
- address: string
|
6
|
-
- created_at: datetime
|
7
|
-
- updated_at: datetime
|
8
9
|
relations:
|
9
10
|
has_many:
|
10
11
|
- users
|
11
12
|
users:
|
12
13
|
columns:
|
13
|
-
- id: integer
|
14
14
|
- crypted_password: string
|
15
15
|
- email: string
|
16
16
|
- password_salt: string
|
17
17
|
- auth_token: string
|
18
18
|
- company_id: integer
|
19
|
-
- created_at: datetime
|
20
|
-
- updated_at: datetime
|
21
19
|
- deleted_at: datetime
|
22
20
|
index:
|
23
21
|
- email
|
@@ -29,34 +27,25 @@ users:
|
|
29
27
|
- user_logs
|
30
28
|
roles:
|
31
29
|
columns:
|
32
|
-
- id: integer
|
33
30
|
- title: string
|
34
31
|
- user_id: intger
|
35
|
-
- created_at: datetime
|
36
|
-
- updated_at: datetime
|
37
32
|
relations:
|
38
33
|
belongs_to:
|
39
34
|
- users
|
40
35
|
user_logs:
|
41
36
|
columns:
|
42
|
-
- id: integer
|
43
37
|
- recently_signed_in: datetime
|
44
38
|
- user_id: integer
|
45
|
-
- created_at: datetime
|
46
|
-
- updated_at: datetime
|
47
39
|
relations:
|
48
40
|
belongs_to:
|
49
41
|
- users
|
50
42
|
posts:
|
51
43
|
columns:
|
52
|
-
- id: integer
|
53
44
|
- title: string
|
54
45
|
- body: text
|
55
46
|
- attachment_path: string
|
56
47
|
- deleted_at: datetime
|
57
48
|
- user_id: integer
|
58
|
-
- created_at: datetime
|
59
|
-
- updated_at: datetime
|
60
49
|
index:
|
61
50
|
- user_id
|
62
51
|
relations:
|
data/yml2erd.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["suenagaryoutaabc@gmail.com"]
|
11
11
|
|
12
12
|
spec.summary = %q{This gem allows us to generate an erd easily.}
|
13
|
-
spec.description = %q{
|
13
|
+
spec.description = %q{This gem generates erd from a simple yml.}
|
14
14
|
spec.homepage = "https://github.com/asmsuechan/yml2erd"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yml2erd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- asmsuechan
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-12-
|
11
|
+
date: 2016-12-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby-graphviz
|
@@ -136,7 +136,7 @@ dependencies:
|
|
136
136
|
- - ">="
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
|
-
description:
|
139
|
+
description: This gem generates erd from a simple yml.
|
140
140
|
email:
|
141
141
|
- suenagaryoutaabc@gmail.com
|
142
142
|
executables:
|