schema_doc 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +10 -0
- data/README.md +2 -2
- data/example/sample_output.md +6 -6
- data/lib/schema_doc/document.rb +17 -21
- data/lib/schema_doc/tasks.rake +1 -3
- data/lib/schema_doc/templates/document_body.md.erb +8 -0
- data/lib/schema_doc/templates/document_header.md.erb +2 -0
- data/lib/schema_doc/version.rb +1 -1
- data/spec/helper.rb +3 -2
- data/spec/locales/en.yml +11 -0
- data/spec/schema_doc/document_spec.rb +8 -11
- metadata +21 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 945b668542d7ca6ce2747238aab184eebf785ef3
|
4
|
+
data.tar.gz: cba9b8b01be7cd9f11791d29cf22c6a2a7d23713
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ac791f0e09c56b5d0274d33cc16874958b1c98c1ef7f207896580986e7234e3af19cf9bb3e6012f5af679d703fe19e0773c1b4d941605bae5ee6ad1a2cd7544
|
7
|
+
data.tar.gz: fb4883567774acb4311d06190e7415905c94eda1a8fa3f91743a7a604d80cad544ec0df7fd6369aa60a4d698052cd4115774f8e761ff41c2dc51d5015ff1de8b
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# SchemaDoc
|
1
|
+
# SchemaDoc [![Build Status](https://secure.travis-ci.org/mizoR/schema_doc.png)](https://travis-ci.org/mizoR/schema_doc)
|
2
2
|
|
3
3
|
SchemaDoc outputs database schema for your Rails applications in markdown style
|
4
4
|
|
@@ -6,7 +6,7 @@ SchemaDoc outputs database schema for your Rails applications in markdown style
|
|
6
6
|
|
7
7
|
Add this line to your application's Gemfile:
|
8
8
|
|
9
|
-
gem 'schema_doc'
|
9
|
+
gem 'schema_doc'
|
10
10
|
|
11
11
|
And then execute:
|
12
12
|
|
data/example/sample_output.md
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
|
2
1
|
# blogs
|
3
2
|
|
4
3
|
## Blog
|
@@ -6,9 +5,10 @@
|
|
6
5
|
| name | human name | sql type | primary | default | limit |
|
7
6
|
| ---- | ---------- | -------- | ------- | ------- | ----- |
|
8
7
|
| id | Id | INTEGER | true | | |
|
9
|
-
| name | Name | varchar(255) | false | | 255 |
|
8
|
+
| name | Blog Name | varchar(255) | false | | 255 |
|
10
9
|
| owner_id | Owner | integer | false | | |
|
11
10
|
|
11
|
+
|
12
12
|
# entries
|
13
13
|
|
14
14
|
## Entry
|
@@ -16,8 +16,9 @@
|
|
16
16
|
| name | human name | sql type | primary | default | limit |
|
17
17
|
| ---- | ---------- | -------- | ------- | ------- | ----- |
|
18
18
|
| id | Id | INTEGER | true | | |
|
19
|
-
| title | Title | varchar(255) | false | | 255 |
|
20
|
-
| body | Body | varchar(255) | false | | 255 |
|
19
|
+
| title | Entry Title | varchar(255) | false | | 255 |
|
20
|
+
| body | Entry Body | varchar(255) | false | | 255 |
|
21
|
+
|
21
22
|
|
22
23
|
# users
|
23
24
|
|
@@ -26,5 +27,4 @@
|
|
26
27
|
| name | human name | sql type | primary | default | limit |
|
27
28
|
| ---- | ---------- | -------- | ------- | ------- | ----- |
|
28
29
|
| id | Id | INTEGER | true | | |
|
29
|
-
| nick |
|
30
|
-
|
30
|
+
| nick | Nickname | varchar(255) | false | | 255 |
|
data/lib/schema_doc/document.rb
CHANGED
@@ -6,8 +6,8 @@ module SchemaDoc
|
|
6
6
|
def read
|
7
7
|
document = []
|
8
8
|
|
9
|
-
|
10
|
-
document <<
|
9
|
+
model_classes_group_by_table_name.sort.each do |table_name, model_classes|
|
10
|
+
document << table_document(table_name, model_classes)
|
11
11
|
end
|
12
12
|
|
13
13
|
document.join
|
@@ -15,30 +15,26 @@ module SchemaDoc
|
|
15
15
|
|
16
16
|
private
|
17
17
|
|
18
|
-
def
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
<% descendant.columns.each do |column| %>| <%= column.name %> | <%= descendant.human_attribute_name(column.name) %> | <%= column.sql_type %> | <%= column.primary %> | <%= column.default %> | <%= column.limit %> |
|
30
|
-
<% end %>
|
31
|
-
MARKDOWN
|
32
|
-
end
|
18
|
+
def table_document(table_name, model_classes)
|
19
|
+
template_path = SchemaDoc.root + '/lib/schema_doc/templates/document_header.md.erb'
|
20
|
+
ERB.new(File.read(template_path)).result(binding)
|
21
|
+
"# #{table_name}\n" + model_classes.map { |model_class|
|
22
|
+
model_document(table_name, model_class)
|
23
|
+
}.join
|
24
|
+
end
|
25
|
+
|
26
|
+
def model_document(table_name, model_class)
|
27
|
+
template_path = SchemaDoc.root + '/lib/schema_doc/templates/document_body.md.erb'
|
28
|
+
ERB.new(File.read(template_path)).result(binding)
|
33
29
|
end
|
34
30
|
|
35
|
-
def
|
31
|
+
def model_classes
|
36
32
|
ActiveRecord::Base.descendants
|
37
33
|
end
|
38
34
|
|
39
|
-
def
|
40
|
-
|
41
|
-
|
35
|
+
def model_classes_group_by_table_name
|
36
|
+
model_classes.select(&:table_exists?).group_by {|model_class|
|
37
|
+
model_class.table_name
|
42
38
|
}
|
43
39
|
end
|
44
40
|
end
|
data/lib/schema_doc/tasks.rake
CHANGED
@@ -1,9 +1,7 @@
|
|
1
1
|
namespace :schema_doc do
|
2
2
|
task :out => :environment do
|
3
3
|
require 'schema_doc'
|
4
|
-
|
5
|
-
require path
|
6
|
-
end
|
4
|
+
Rails.application.eager_load!
|
7
5
|
puts SchemaDoc::Document.read if !Rake.application.options.silent
|
8
6
|
end
|
9
7
|
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
<%# coding: UTF-8 %>
|
2
|
+
## <%= model_class %>
|
3
|
+
|
4
|
+
| name | human name | sql type | primary | default | limit |
|
5
|
+
| ---- | ---------- | -------- | ------- | ------- | ----- |
|
6
|
+
<% model_class.columns.each do |column| %>| <%= column.name %> | <%= model_class.human_attribute_name(column.name) %> | <%= column.sql_type %> | <%= model_class.primary_key.eql?(column.name) %> | <%= column.default %> | <%= column.limit %> |
|
7
|
+
<% end %>
|
8
|
+
|
data/lib/schema_doc/version.rb
CHANGED
data/spec/helper.rb
CHANGED
@@ -2,11 +2,13 @@ require 'schema_doc'
|
|
2
2
|
require 'active_record'
|
3
3
|
|
4
4
|
dbfile = File.join(SchemaDoc.root, 'spec/db/test.sqlite3')
|
5
|
-
|
6
5
|
if File.exist?(dbfile)
|
7
6
|
File.delete(dbfile)
|
8
7
|
end
|
9
8
|
|
9
|
+
locales_dir = File.join(SchemaDoc.root, 'spec/locales')
|
10
|
+
I18n.load_path << locales_dir + '/en.yml'
|
11
|
+
|
10
12
|
ActiveRecord::Base.establish_connection(
|
11
13
|
'adapter' => 'sqlite3',
|
12
14
|
'database' => dbfile
|
@@ -64,4 +66,3 @@ end
|
|
64
66
|
class Entry < ActiveRecord::Base
|
65
67
|
belongs_to :blog
|
66
68
|
end
|
67
|
-
|
data/spec/locales/en.yml
ADDED
@@ -1,12 +1,9 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
3
|
describe SchemaDoc::Document do
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
describe 'send(:template)' do
|
8
|
-
let :template do
|
9
|
-
SchemaDoc::Document.send(:template, *args)
|
4
|
+
describe 'send(:table_document)' do
|
5
|
+
let :document do
|
6
|
+
SchemaDoc::Document.send(:table_document, *args)
|
10
7
|
end
|
11
8
|
|
12
9
|
context 'When table is "users"' do
|
@@ -15,27 +12,27 @@ describe SchemaDoc::Document do
|
|
15
12
|
end
|
16
13
|
|
17
14
|
it 'matches table name' do
|
18
|
-
expect(
|
15
|
+
expect(document).to match(/^# #{args[0]}$/)
|
19
16
|
end
|
20
17
|
|
21
18
|
it 'matches model name' do
|
22
19
|
args[1].each do |model|
|
23
|
-
expect(
|
20
|
+
expect(document).to match(/^## #{model.to_s}$/)
|
24
21
|
end
|
25
22
|
end
|
26
23
|
|
27
24
|
it 'matches header ' do
|
28
|
-
expect(
|
25
|
+
expect(document).to match(/^| name | human name | sql type | primary | default | limit |$/)
|
29
26
|
end
|
30
27
|
|
31
28
|
it 'matches separator ' do
|
32
|
-
expect(
|
29
|
+
expect(document).to match(/^| ---- | ---------- | -------- | ------- | ------- | ----- |$/)
|
33
30
|
end
|
34
31
|
|
35
32
|
it 'matches some columns ' do
|
36
33
|
args[1].each do |model|
|
37
34
|
model.columns.each do |column|
|
38
|
-
expect(
|
35
|
+
expect(document).to match(/^| #{column.name} | /)
|
39
36
|
end
|
40
37
|
end
|
41
38
|
end
|
metadata
CHANGED
@@ -1,83 +1,83 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schema_doc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mizokami
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-10-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.3'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.3'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 3.2.16
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 3.2.16
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: activerecord
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: sqlite3
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
description: Output database schema in markdown style.
|
@@ -87,7 +87,8 @@ executables: []
|
|
87
87
|
extensions: []
|
88
88
|
extra_rdoc_files: []
|
89
89
|
files:
|
90
|
-
- .gitignore
|
90
|
+
- ".gitignore"
|
91
|
+
- ".travis.yml"
|
91
92
|
- Gemfile
|
92
93
|
- LICENSE.txt
|
93
94
|
- README.md
|
@@ -97,10 +98,13 @@ files:
|
|
97
98
|
- lib/schema_doc/document.rb
|
98
99
|
- lib/schema_doc/railtie.rb
|
99
100
|
- lib/schema_doc/tasks.rake
|
101
|
+
- lib/schema_doc/templates/document_body.md.erb
|
102
|
+
- lib/schema_doc/templates/document_header.md.erb
|
100
103
|
- lib/schema_doc/version.rb
|
101
104
|
- schema_doc.gemspec
|
102
105
|
- spec/db/.gitkeep
|
103
106
|
- spec/helper.rb
|
107
|
+
- spec/locales/en.yml
|
104
108
|
- spec/schema_doc/document_spec.rb
|
105
109
|
- spec/schema_doc_spec.rb
|
106
110
|
homepage: ''
|
@@ -113,22 +117,23 @@ require_paths:
|
|
113
117
|
- lib
|
114
118
|
required_ruby_version: !ruby/object:Gem::Requirement
|
115
119
|
requirements:
|
116
|
-
- -
|
120
|
+
- - ">="
|
117
121
|
- !ruby/object:Gem::Version
|
118
122
|
version: '0'
|
119
123
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
124
|
requirements:
|
121
|
-
- -
|
125
|
+
- - ">="
|
122
126
|
- !ruby/object:Gem::Version
|
123
127
|
version: '0'
|
124
128
|
requirements: []
|
125
129
|
rubyforge_project:
|
126
|
-
rubygems_version: 2.
|
130
|
+
rubygems_version: 2.5.1
|
127
131
|
signing_key:
|
128
132
|
specification_version: 4
|
129
133
|
summary: Output database schema in markdown style.
|
130
134
|
test_files:
|
131
135
|
- spec/db/.gitkeep
|
132
136
|
- spec/helper.rb
|
137
|
+
- spec/locales/en.yml
|
133
138
|
- spec/schema_doc/document_spec.rb
|
134
139
|
- spec/schema_doc_spec.rb
|