schema_comments 0.3.0 → 0.3.1
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/README.md +94 -101
- data/lib/schema_comments/railtie.rb +1 -0
- data/lib/schema_comments/version.rb +1 -1
- data/lib/schema_comments.rb +1 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb906aa319149d9162686075b61ccaa340f1fd38
|
4
|
+
data.tar.gz: 91ba3034e9efc564abfe4e7b556639fc606a5c6a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b83e84536e4770de6e2231c9c6b712ce299ed3bb7610e847d0ba004050455d5d3a9e35d6d88ad809e67e8c8075757a5ad276370ab37363869c2f572a6a8b8ca
|
7
|
+
data.tar.gz: 5ac5502337703798c29e059d1bfaa7efbffdde85a2148cd88143e9ea40f579849638910107190be71f2e975952e0243f8b800c3dab2edf33f4e6e6296a8e0d01
|
data/README.md
CHANGED
@@ -5,89 +5,67 @@
|
|
5
5
|
### With Bundler
|
6
6
|
add this line into Gemfile
|
7
7
|
|
8
|
-
|
8
|
+
```
|
9
|
+
gem "schema_comments"
|
10
|
+
```
|
9
11
|
|
10
12
|
And do bundle install
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
### as a plugin
|
17
|
-
|
18
|
-
ruby script/plugin install git://github.com/akm/schema_comments.git
|
19
|
-
|
20
|
-
### as a gem
|
21
|
-
insert following line to config/environment.rb
|
22
|
-
|
23
|
-
config.gem 'schema_comments', :version => '0.2.0'
|
24
|
-
|
25
|
-
and
|
26
|
-
|
27
|
-
$ sudo rake gems:install
|
14
|
+
```
|
15
|
+
bundle install
|
16
|
+
```
|
28
17
|
|
29
18
|
Or install gem manually
|
30
19
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
require 'schema_comments/task'
|
36
|
-
|
37
|
-
## Configuration for Rails App
|
38
|
-
1. make lib/tasks/schema_comments.rake
|
39
|
-
2. edit the file like following
|
40
|
-
|
41
|
-
require 'schema_comments/task'
|
42
|
-
SchemaComments.yaml_path = File.expand_path("../../../db/schema_comments.yml", __FILE__)
|
43
|
-
|
44
|
-
|
45
|
-
## Configuration (old)
|
46
|
-
If you install schema_comments as a gem, must create config/initializers/schema_comments.rb like this:
|
47
|
-
|
48
|
-
require 'schema_comments'
|
49
|
-
SchemaComments.setup
|
20
|
+
```
|
21
|
+
$ gem install schema_comments
|
22
|
+
```
|
50
23
|
|
51
24
|
|
52
25
|
## Overview
|
53
26
|
schema_commentsプラグインを使うと、テーブルとカラムにコメントを記述することができます。
|
54
27
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
end
|
65
|
-
|
66
|
-
def self.down
|
67
|
-
drop_table "products"
|
68
|
-
end
|
28
|
+
```
|
29
|
+
class CreateProducts < ActiveRecord::Migration
|
30
|
+
def self.up
|
31
|
+
create_table "products", :comment => '商品' do |t|
|
32
|
+
t.string "product_type_cd", :comment => '種別コード'
|
33
|
+
t.integer "price", :comment => "価格"
|
34
|
+
t.string "name", :comment => "商品名"
|
35
|
+
t.datetime "created_at", :comment => "登録日時"
|
36
|
+
t.datetime "updated_at", :comment => "更新日時"
|
69
37
|
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.down
|
41
|
+
drop_table "products"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
```
|
70
45
|
|
71
46
|
こんな感じ。
|
72
47
|
|
73
48
|
でこのようなマイグレーションを実行すると、db/schema.rb には、
|
74
49
|
コメントが設定されているテーブル、カラムは以下のように出力されます。
|
75
50
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
51
|
+
```
|
52
|
+
ActiveRecord::Schema.define(:version => 0) do
|
53
|
+
create_table "products", :force => true, :comment => '商品' do |t|
|
54
|
+
t.string "product_type_cd", :comment => '種別コード'
|
55
|
+
t.integer "price", :comment => "価格"
|
56
|
+
t.string "name", :comment => "商品名"
|
57
|
+
t.datetime "created_at", :comment => "登録日時"
|
58
|
+
t.datetime "updated_at", :comment => "更新日時"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
```
|
86
62
|
|
87
63
|
コメントは、以下のメソッドで使用することが可能です。
|
88
64
|
|
65
|
+
```
|
89
66
|
columns, create_table, drop_table, rename_table
|
90
67
|
remove_column, add_column, change_column
|
68
|
+
```
|
91
69
|
|
92
70
|
|
93
71
|
## コメントはどこに保存されるのか
|
@@ -98,53 +76,66 @@ db/schema_comments.yml にYAML形式で保存されます。
|
|
98
76
|
|
99
77
|
## I18nへの対応
|
100
78
|
|
101
|
-
|
79
|
+
```
|
80
|
+
rake i18n:schema_comments:update_config_locale
|
81
|
+
```
|
102
82
|
|
103
83
|
このタスクを実行すると、i18n用のYAMLを更新できます。
|
104
84
|
|
105
|
-
|
85
|
+
```
|
86
|
+
rake i18n:schema_comments:update_config_locale LOCALE=ja
|
87
|
+
```
|
106
88
|
|
107
89
|
でデフォルトではconfig/locales/ja.ymlを更新します。
|
108
90
|
|
109
91
|
毎回LOCALEを指定するのが面倒な場合は、config/initializers/locale.rb に
|
110
92
|
|
111
|
-
|
93
|
+
```
|
94
|
+
I18n.default_locale = 'ja'
|
95
|
+
```
|
112
96
|
|
113
97
|
という記述を追加しておくと良いでしょう。
|
114
98
|
|
115
99
|
また出力先のYAMLのPATHを指定したい場合、YAML_PATHで指定が可能です。
|
116
100
|
|
117
|
-
|
101
|
+
```
|
102
|
+
rake i18n:schema_comments:update_config_locale LOCALE=ja YAML_PATH=/path/to/yaml
|
103
|
+
```
|
118
104
|
|
119
105
|
### コメント内コメント
|
120
106
|
コメント中の ((( から ))) は反映されませんので、モデル名/属性名に含めたくない箇所は ((( と ))) で括ってください。
|
121
107
|
((( ))) と同様に[[[ ]]]も使用できます。
|
122
108
|
例えば以下のようにdb/schema.rbに出力されている場合、
|
123
109
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
110
|
+
```
|
111
|
+
ActiveRecord::Schema.define(:version => 0) do
|
112
|
+
create_table "products", :force => true, :comment => '商品' do |t|
|
113
|
+
t.string "product_type_cd", :comment => '種別コード(((01:書籍, 02:靴, 03:パソコン)))'
|
114
|
+
t.integer "price", :comment => "価格"
|
115
|
+
t.string "name", :comment => "商品名"
|
116
|
+
t.datetime "created_at", :comment => "登録日時"
|
117
|
+
t.datetime "updated_at", :comment => "更新日時"
|
118
|
+
end
|
119
|
+
end
|
120
|
+
```
|
121
|
+
|
122
|
+
```
|
123
|
+
$ rake i18n:schema_comments:update_config_locale LOCALE=ja
|
124
|
+
```
|
136
125
|
|
137
126
|
とすると、以下のように出力されます。
|
138
127
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
128
|
+
```
|
129
|
+
ja:
|
130
|
+
activerecord:
|
131
|
+
attributes:
|
132
|
+
product:
|
133
|
+
product_type_cd: "種別コード"
|
134
|
+
price: "価格"
|
135
|
+
name: "商品名"
|
136
|
+
created_at: "登録日時"
|
137
|
+
updated_at: "更新日時"
|
138
|
+
```
|
148
139
|
|
149
140
|
|
150
141
|
|
@@ -159,22 +150,24 @@ test環境ではテーブルとして作成されてしまい、テストが正
|
|
159
150
|
rake db:annotate で以下のようなコメントを、モデル、テスト、フィクスチャといったモデルに関係の強いファイルの
|
160
151
|
先頭に追加します。
|
161
152
|
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
153
|
+
```
|
154
|
+
# == Schema Info
|
155
|
+
#
|
156
|
+
# Schema version: 20090721185959
|
157
|
+
#
|
158
|
+
# Table name: books # 書籍
|
159
|
+
#
|
160
|
+
# id :integer not null, primary key
|
161
|
+
# title :string(100) not null # タイトル
|
162
|
+
# size :integer not null, default(1) # 判型
|
163
|
+
# price :decimal(17, 14) not null, default(0.0) # 価格
|
164
|
+
# created_at :datetime # 登録日時
|
165
|
+
# updated_at :datetime # 更新日時
|
166
|
+
#
|
167
|
+
# =================
|
168
|
+
#
|
169
|
+
```
|
170
|
+
|
178
171
|
また、rake db:updateで、rake db:migrateとrake db:annotateを実行します。
|
179
172
|
|
180
173
|
annotate_modelsは、達人プログラマーのDave Thomasさんが公開しているプラグインです。
|
data/lib/schema_comments.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'active_support/core_ext/module'
|
2
2
|
|
3
|
+
require 'schema_comments/version'
|
3
4
|
require 'schema_comments/railtie'
|
4
5
|
|
5
6
|
module SchemaComments
|
6
|
-
VERSION = File.read(File.expand_path("../../VERSION", __FILE__))
|
7
7
|
|
8
8
|
autoload :Base , 'schema_comments/base'
|
9
9
|
autoload :ConnectionAdapters, 'schema_comments/connection_adapters'
|
@@ -14,8 +14,6 @@ module SchemaComments
|
|
14
14
|
autoload :SchemaDumper , 'schema_comments/schema_dumper'
|
15
15
|
|
16
16
|
mattr_accessor :yaml_path
|
17
|
-
self.yaml_path = Rails.root.join("db/schema_comments.yml").to_s if defined?(Rails) && Rails.root
|
18
|
-
|
19
17
|
mattr_accessor :quiet
|
20
18
|
|
21
19
|
class YamlError < StandardError
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schema_comments
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- akm
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|