aam 0.0.11 → 0.0.13
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 +1 -3
- data/README.org +10 -10
- data/aam.gemspec +1 -1
- data/examples/0100_example.rb +40 -40
- data/lib/aam/annotation.rb +2 -2
- data/lib/aam/{schema_info_generator.rb → generator.rb} +24 -23
- data/lib/aam/version.rb +1 -1
- data/lib/aam.rb +1 -1
- data/test/test_aam.rb +40 -40
- data/test/test_helper.rb +1 -0
- metadata +8 -13
- data/.travis.yml +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 916499d13ede92b2380ca245157b0899f3ff71c32a8508461f540d07d30053b7
|
4
|
+
data.tar.gz: 0b012bbe95747089e3f1f00abb7a354ef1778b5442b2dd99c3d72b8945fff6e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e682b10b803d6995da0ecd53d3cd1f2025d8043b3b264490d982f3fda80220c2f9e6186ce6e9d1304306cfb75e999a735dcb628a19d4e3c9b14740a896c7613b
|
7
|
+
data.tar.gz: a74c2f74ee0d15213f111e326ff702720cad2c03f862debc7d0b3bff3946a4a9c728fed9d5474b24366e168d34895820fd8b8bf098cc980ad9bb7d25c236d398
|
data/Gemfile
CHANGED
data/README.org
CHANGED
@@ -37,7 +37,7 @@ ActiveRecord::Schema.define do
|
|
37
37
|
|
38
38
|
create_table :articles do |t|
|
39
39
|
t.belongs_to :user, index: true
|
40
|
-
t.belongs_to :foo, :
|
40
|
+
t.belongs_to :foo, polymorphic: true, :index => false
|
41
41
|
end
|
42
42
|
|
43
43
|
create_table :blogs do |t|
|
@@ -53,7 +53,7 @@ end
|
|
53
53
|
|
54
54
|
class Article < ActiveRecord::Base
|
55
55
|
belongs_to :user
|
56
|
-
belongs_to :foo, :
|
56
|
+
belongs_to :foo, polymorphic: true
|
57
57
|
end
|
58
58
|
|
59
59
|
class Blog < ActiveRecord::Base
|
@@ -64,7 +64,7 @@ class SubArticle < Article
|
|
64
64
|
belongs_to :blog, :class_name => "Blog", :foreign_key => :foo_id
|
65
65
|
end
|
66
66
|
|
67
|
-
puts Aam::
|
67
|
+
puts Aam::Generator.new(User).generate
|
68
68
|
# >> # == Schema Information ==
|
69
69
|
# >> #
|
70
70
|
# >> # Userテーブル (users as User)
|
@@ -77,7 +77,7 @@ puts Aam::SchemaInfoGenerator.new(User).generate
|
|
77
77
|
# >> # | flag | Flag | boolean | DEFAULT(f) | | |
|
78
78
|
# >> # +----------+------+---------+-------------+------+-------+
|
79
79
|
|
80
|
-
puts Aam::
|
80
|
+
puts Aam::Generator.new(Article).generate
|
81
81
|
# >> # == Schema Information ==
|
82
82
|
# >> #
|
83
83
|
# >> # Articleテーブル (articles as Article)
|
@@ -87,16 +87,16 @@ puts Aam::SchemaInfoGenerator.new(Article).generate
|
|
87
87
|
# >> # +----------+----------+---------+-------------+-----------------------+-------+
|
88
88
|
# >> # | id | Id | integer | NOT NULL PK | | |
|
89
89
|
# >> # | user_id | ユーザー | integer | | => User#id | A |
|
90
|
-
# >> # | foo_type | Foo type | string | |
|
90
|
+
# >> # | foo_type | Foo type | string | | SpecificModel(polymorphic) | |
|
91
91
|
# >> # | foo_id | Foo | integer | | => (foo_type)#id | |
|
92
92
|
# >> # +----------+----------+---------+-------------+-----------------------+-------+
|
93
93
|
# >> #
|
94
94
|
# >> #- 備考 -------------------------------------------------------------------------
|
95
95
|
# >> # ・Article モデルは User モデルから has_many :articles されています。
|
96
|
-
# >> #
|
96
|
+
# >> # ・[Warning: Need to add index]create_articles マイグレーションに add_index :articles, [:foo_id, :foo_type] を追加してください
|
97
97
|
# >> #--------------------------------------------------------------------------------
|
98
98
|
|
99
|
-
puts Aam::
|
99
|
+
puts Aam::Generator.new(Blog).generate
|
100
100
|
# >> # == Schema Information ==
|
101
101
|
# >> #
|
102
102
|
# >> # Blogテーブル (blogs as Blog)
|
@@ -108,7 +108,7 @@ puts Aam::SchemaInfoGenerator.new(Blog).generate
|
|
108
108
|
# >> # | name | Name | string | | | |
|
109
109
|
# >> # +----------+------+---------+-------------+------+-------+
|
110
110
|
|
111
|
-
puts Aam::
|
111
|
+
puts Aam::Generator.new(SubArticle).generate
|
112
112
|
# >> # == Schema Information ==
|
113
113
|
# >> #
|
114
114
|
# >> # なんとかテーブル (articles as SubArticle)
|
@@ -118,13 +118,13 @@ puts Aam::SchemaInfoGenerator.new(SubArticle).generate
|
|
118
118
|
# >> # +----------+----------+---------+-------------+--------------------------------------+-------+
|
119
119
|
# >> # | id | Id | integer | NOT NULL PK | | |
|
120
120
|
# >> # | user_id | ユーザー | integer | | => User#id | A |
|
121
|
-
# >> # | foo_type | Foo type | string | |
|
121
|
+
# >> # | foo_type | Foo type | string | | SpecificModel(polymorphic) | |
|
122
122
|
# >> # | foo_id | Foo | integer | | :blog => Blog#id と => (foo_type)#id | |
|
123
123
|
# >> # +----------+----------+---------+-------------+--------------------------------------+-------+
|
124
124
|
# >> #
|
125
125
|
# >> #- 備考 -------------------------------------------------------------------------
|
126
126
|
# >> # ・SubArticle モデルは User モデルから has_many :articles されています。
|
127
|
-
# >> #
|
127
|
+
# >> # ・[Warning: Need to add index]create_articles マイグレーションに add_index :articles, [:foo_id, :foo_type] を追加してください
|
128
128
|
# >> # ・SubArticle モデルは Blog モデルから has_many :sub_articles, :foreign_key => :foo_id されています。
|
129
129
|
# >> #--------------------------------------------------------------------------------
|
130
130
|
#+END_SRC
|
data/aam.gemspec
CHANGED
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_development_dependency "bundler"
|
21
|
+
spec.add_development_dependency "bundler"
|
22
22
|
spec.add_development_dependency "rake"
|
23
23
|
spec.add_development_dependency "test-unit"
|
24
24
|
spec.add_development_dependency "sqlite3"
|
data/examples/0100_example.rb
CHANGED
@@ -13,7 +13,7 @@ ActiveRecord::Schema.define do
|
|
13
13
|
|
14
14
|
create_table :articles do |t|
|
15
15
|
t.belongs_to :user, index: true
|
16
|
-
t.belongs_to :foo, :
|
16
|
+
t.belongs_to :foo, polymorphic: true, :index => false # Rails5からindex:trueがデフォルトになっているため
|
17
17
|
end
|
18
18
|
|
19
19
|
create_table :blogs do |t|
|
@@ -29,7 +29,7 @@ end
|
|
29
29
|
|
30
30
|
class Article < ActiveRecord::Base
|
31
31
|
belongs_to :user
|
32
|
-
belongs_to :foo, :
|
32
|
+
belongs_to :foo, polymorphic: true
|
33
33
|
end
|
34
34
|
|
35
35
|
class Blog < ActiveRecord::Base
|
@@ -49,64 +49,64 @@ if true
|
|
49
49
|
I18n.backend.store_translations :ja, {:activerecord => {:models => {"sub_article" => "なんとか"} }, :attributes => {"user_id" => "ユーザー"}}
|
50
50
|
end
|
51
51
|
|
52
|
-
puts Aam::
|
53
|
-
puts Aam::
|
54
|
-
puts Aam::
|
55
|
-
puts Aam::
|
52
|
+
puts Aam::Generator.new(User).generate
|
53
|
+
puts Aam::Generator.new(Article).generate
|
54
|
+
puts Aam::Generator.new(Blog).generate
|
55
|
+
puts Aam::Generator.new(SubArticle).generate
|
56
56
|
|
57
57
|
# >> # == Schema Information ==
|
58
58
|
# >> #
|
59
|
-
# >> # User
|
59
|
+
# >> # User (users as User)
|
60
60
|
# >> #
|
61
|
-
# >> #
|
62
|
-
# >> # |
|
63
|
-
# >> #
|
64
|
-
# >> # | id
|
65
|
-
# >> # | name
|
66
|
-
# >> # | flag
|
67
|
-
# >> #
|
61
|
+
# >> # |------+------+---------+-------------+------+-------|
|
62
|
+
# >> # | name | desc | type | opts | refs | index |
|
63
|
+
# >> # |------+------+---------+-------------+------+-------|
|
64
|
+
# >> # | id | Id | integer | NOT NULL PK | | |
|
65
|
+
# >> # | name | Name | string | | | A! |
|
66
|
+
# >> # | flag | Flag | boolean | DEFAULT(f) | | |
|
67
|
+
# >> # |------+------+---------+-------------+------+-------|
|
68
68
|
# >> # == Schema Information ==
|
69
69
|
# >> #
|
70
|
-
# >> # Article
|
70
|
+
# >> # Article (articles as Article)
|
71
71
|
# >> #
|
72
|
-
# >> #
|
73
|
-
# >> # |
|
74
|
-
# >> #
|
75
|
-
# >> # | id | Id | integer | NOT NULL PK |
|
76
|
-
# >> # | user_id | ユーザー | integer | | => User#id
|
77
|
-
# >> # | foo_type | Foo type | string | |
|
78
|
-
# >> # | foo_id | Foo | integer | | => (foo_type)#id
|
79
|
-
# >> #
|
72
|
+
# >> # |----------+----------+---------+-------------+----------------------------+-------|
|
73
|
+
# >> # | name | desc | type | opts | refs | index |
|
74
|
+
# >> # |----------+----------+---------+-------------+----------------------------+-------|
|
75
|
+
# >> # | id | Id | integer | NOT NULL PK | | |
|
76
|
+
# >> # | user_id | ユーザー | integer | | => User#id | A |
|
77
|
+
# >> # | foo_type | Foo type | string | | SpecificModel(polymorphic) | |
|
78
|
+
# >> # | foo_id | Foo | integer | | => (foo_type)#id | |
|
79
|
+
# >> # |----------+----------+---------+-------------+----------------------------+-------|
|
80
80
|
# >> #
|
81
|
-
# >> #-
|
82
|
-
# >> #
|
83
|
-
# >> #
|
81
|
+
# >> #- Remarks ----------------------------------------------------------------------
|
82
|
+
# >> # User.has_many :articles
|
83
|
+
# >> # [Warning: Need to add index] create_articles マイグレーションに add_index :articles, [:foo_id, :foo_type] を追加してください
|
84
84
|
# >> #--------------------------------------------------------------------------------
|
85
85
|
# >> # == Schema Information ==
|
86
86
|
# >> #
|
87
|
-
# >> # Blog
|
87
|
+
# >> # Blog (blogs as Blog)
|
88
88
|
# >> #
|
89
|
-
# >> #
|
90
|
-
# >> # |
|
91
|
-
# >> #
|
92
|
-
# >> # | id
|
93
|
-
# >> # | name
|
94
|
-
# >> #
|
89
|
+
# >> # |------+------+---------+-------------+------+-------|
|
90
|
+
# >> # | name | desc | type | opts | refs | index |
|
91
|
+
# >> # |------+------+---------+-------------+------+-------|
|
92
|
+
# >> # | id | Id | integer | NOT NULL PK | | |
|
93
|
+
# >> # | name | Name | string | | | |
|
94
|
+
# >> # |------+------+---------+-------------+------+-------|
|
95
95
|
# >> # == Schema Information ==
|
96
96
|
# >> #
|
97
|
-
# >> #
|
97
|
+
# >> # なんとか (articles as SubArticle)
|
98
98
|
# >> #
|
99
99
|
# >> # |----------+----------+---------+-------------+--------------------------------------+-------|
|
100
|
-
# >> # |
|
100
|
+
# >> # | name | desc | type | opts | refs | index |
|
101
101
|
# >> # |----------+----------+---------+-------------+--------------------------------------+-------|
|
102
102
|
# >> # | id | Id | integer | NOT NULL PK | | |
|
103
103
|
# >> # | user_id | ユーザー | integer | | => User#id | A |
|
104
|
-
# >> # | foo_type | Foo type | string | |
|
104
|
+
# >> # | foo_type | Foo type | string | | SpecificModel(polymorphic) | |
|
105
105
|
# >> # | foo_id | Foo | integer | | :blog => Blog#id と => (foo_type)#id | |
|
106
106
|
# >> # |----------+----------+---------+-------------+--------------------------------------+-------|
|
107
107
|
# >> #
|
108
|
-
# >> #-
|
109
|
-
# >> #
|
110
|
-
# >> #
|
111
|
-
# >> #
|
108
|
+
# >> #- Remarks ----------------------------------------------------------------------
|
109
|
+
# >> # Blog.has_many :sub_articles, foreign_key: :foo_id
|
110
|
+
# >> # User.has_many :articles
|
111
|
+
# >> # [Warning: Need to add index] create_articles マイグレーションに add_index :articles, [:foo_id, :foo_type] を追加してください
|
112
112
|
# >> #--------------------------------------------------------------------------------
|
data/lib/aam/annotation.rb
CHANGED
@@ -49,7 +49,7 @@ module Aam
|
|
49
49
|
begin
|
50
50
|
model = Model.new(self, klass)
|
51
51
|
@all << model.schema_info
|
52
|
-
rescue ActiveRecord::ActiveRecordError
|
52
|
+
rescue ActiveRecord::ActiveRecordError
|
53
53
|
end
|
54
54
|
end
|
55
55
|
file = root_dir.join("db", "schema_info.txt")
|
@@ -71,7 +71,7 @@ module Aam
|
|
71
71
|
end
|
72
72
|
|
73
73
|
def schema_info
|
74
|
-
@schema_info ||=
|
74
|
+
@schema_info ||= Generator.new(@klass, @base.options).generate + "\n"
|
75
75
|
end
|
76
76
|
|
77
77
|
def write_to_relation_files
|
@@ -3,7 +3,7 @@ require "active_support/core_ext/string/filters"
|
|
3
3
|
require "table_format"
|
4
4
|
|
5
5
|
module Aam
|
6
|
-
class
|
6
|
+
class Generator
|
7
7
|
def initialize(klass, options = {})
|
8
8
|
@klass = klass
|
9
9
|
@options = {
|
@@ -19,24 +19,24 @@ module Aam
|
|
19
19
|
}
|
20
20
|
rows = columns.collect {|e|
|
21
21
|
{
|
22
|
-
"
|
23
|
-
"
|
24
|
-
"
|
25
|
-
"
|
26
|
-
"
|
27
|
-
"
|
22
|
+
"name" => e.name,
|
23
|
+
"desc" => column_to_human_name(e.name),
|
24
|
+
"type" => column_type_inspect_of(e),
|
25
|
+
"opts" => column_attribute_inspect_of(e),
|
26
|
+
"refs" => reflections_inspect_of(e),
|
27
|
+
"index" => index_info(e),
|
28
28
|
}
|
29
29
|
}
|
30
30
|
out = []
|
31
31
|
out << "#{SCHEMA_HEADER}\n#\n"
|
32
|
-
out << "# #{@klass.model_name.human}
|
32
|
+
out << "# #{@klass.model_name.human} (#{@klass.table_name} as #{@klass.name})\n"
|
33
33
|
out << "#\n"
|
34
34
|
out << rows.to_t.lines.collect { |e| "# #{e}" }.join
|
35
35
|
if @memos.present?
|
36
36
|
out << "#\n"
|
37
|
-
out << "
|
38
|
-
out << @memos.collect{|row|"#
|
39
|
-
out << "
|
37
|
+
out << "# - Remarks ---------------------------------------------------------------------\n"
|
38
|
+
out << @memos.sort.collect { |row| "# #{row}\n" }.join
|
39
|
+
out << "# -------------------------------------------------------------------------------\n"
|
40
40
|
end
|
41
41
|
out.join
|
42
42
|
end
|
@@ -95,7 +95,7 @@ module Aam
|
|
95
95
|
|
96
96
|
def reflections_inspect_ary_of(column)
|
97
97
|
if column.name == @klass.inheritance_column # カラムが "type" のとき
|
98
|
-
return "
|
98
|
+
return "SpecificModel(STI)"
|
99
99
|
end
|
100
100
|
|
101
101
|
index_check(column)
|
@@ -111,14 +111,14 @@ module Aam
|
|
111
111
|
if md = column.name.match(/(\w+)_id\z/)
|
112
112
|
name = md.captures.first
|
113
113
|
if @klass.column_names.include?("#{name}_type")
|
114
|
-
syntax = "belongs_to :#{name}, :
|
114
|
+
syntax = "belongs_to :#{name}, polymorphic: true"
|
115
115
|
else
|
116
116
|
syntax = "belongs_to :#{name}"
|
117
117
|
end
|
118
|
-
memo_puts "
|
118
|
+
memo_puts "[Warning: Need to add relation] #{@klass} モデルに #{syntax} を追加してください"
|
119
119
|
else
|
120
120
|
# "xxx_type" は polymorphic 指定されていることを確認
|
121
|
-
|
121
|
+
_key, reflection = @klass.reflections.find do |key, reflection|
|
122
122
|
_options = reflection.options
|
123
123
|
if true
|
124
124
|
# >= 3.1.3
|
@@ -129,7 +129,7 @@ module Aam
|
|
129
129
|
end
|
130
130
|
end
|
131
131
|
if reflection
|
132
|
-
"
|
132
|
+
"SpecificModel(polymorphic)"
|
133
133
|
end
|
134
134
|
end
|
135
135
|
else
|
@@ -178,7 +178,7 @@ module Aam
|
|
178
178
|
# 理由は belongs_to に foreign_key が指定されたら has_many 側も has_many :foos, :foreign_key => "bar_id" とならないといけないため。
|
179
179
|
#
|
180
180
|
def belongs_to_model_has_many_syntax(column, reflection)
|
181
|
-
|
181
|
+
_assoc_key, assoc_reflection = reflection.class_name.constantize.reflections.find do |assoc_key, assoc_reflection|
|
182
182
|
if false
|
183
183
|
r = reflection.class_name.constantize == assoc_reflection.active_record && [:has_many, :has_one].include?(assoc_reflection.macro)
|
184
184
|
else
|
@@ -187,9 +187,10 @@ module Aam
|
|
187
187
|
if r
|
188
188
|
syntax = ["#{assoc_reflection.macro} :#{assoc_reflection.name}"]
|
189
189
|
if assoc_reflection.options[:foreign_key]
|
190
|
-
syntax << ":
|
190
|
+
syntax << "foreign_key: :#{assoc_reflection.options[:foreign_key]}"
|
191
191
|
end
|
192
|
-
memo_puts "#{@klass.name} モデルは #{assoc_reflection.active_record} モデルから #{syntax.join(', ')} されています。"
|
192
|
+
# memo_puts "#{@klass.name} モデルは #{assoc_reflection.active_record} モデルから #{syntax.join(', ')} されています。"
|
193
|
+
memo_puts "#{assoc_reflection.active_record}.#{syntax.join(', ')}"
|
193
194
|
r
|
194
195
|
end
|
195
196
|
end
|
@@ -251,7 +252,7 @@ module Aam
|
|
251
252
|
# 関係するインデックスに絞る
|
252
253
|
indexes2 = indexes.find_all {|e| e.columns.include?(column.name) }
|
253
254
|
indexes2.collect {|e|
|
254
|
-
mark = ""
|
255
|
+
mark = +""
|
255
256
|
# そのインデックスは何番目にあるかを調べる
|
256
257
|
mark << ("A".."Z").to_a.at(indexes.index(e)).to_s
|
257
258
|
# ユニークなら「!」
|
@@ -289,14 +290,14 @@ module Aam
|
|
289
290
|
#
|
290
291
|
def index_check(column)
|
291
292
|
if column.name.match(/(\w+)_id\z/) || belongs_to_column?(column)
|
292
|
-
# belongs_to :xxx, :
|
293
|
+
# belongs_to :xxx, polymorphic: true の場合は xxx_id と xxx_type のペアでインデックスを貼る
|
293
294
|
if (md = column.name.match(/(\w+)_id\z/)) && (type_column = @klass.columns_hash["#{md.captures.first}_type"])
|
294
295
|
unless index_column?(column) && index_column?(type_column)
|
295
|
-
memo_puts "
|
296
|
+
memo_puts "[Warning: Need to add index] create_#{@klass.table_name} マイグレーションに add_index :#{@klass.table_name}, [:#{column.name}, :#{type_column.name}] を追加してください"
|
296
297
|
end
|
297
298
|
else
|
298
299
|
unless index_column?(column)
|
299
|
-
memo_puts "
|
300
|
+
memo_puts "[Warning: Need to add index] create_#{@klass.table_name} マイグレーションに add_index :#{@klass.table_name}, :#{column.name} を追加してください"
|
300
301
|
end
|
301
302
|
end
|
302
303
|
end
|
data/lib/aam/version.rb
CHANGED
data/lib/aam.rb
CHANGED
data/test/test_aam.rb
CHANGED
@@ -12,14 +12,14 @@ ActiveRecord::Schema.define do
|
|
12
12
|
|
13
13
|
create_table(:articles) do |t|
|
14
14
|
t.belongs_to :user, :index => false
|
15
|
-
t.belongs_to :xxx, :
|
15
|
+
t.belongs_to :xxx, polymorphic: true, :index => false
|
16
16
|
end
|
17
17
|
create_table(:blogs) do |t|
|
18
18
|
t.string :name
|
19
19
|
end
|
20
20
|
create_table(:foos) do |t|
|
21
21
|
t.belongs_to :user, :index => false
|
22
|
-
t.belongs_to :xxx, :
|
22
|
+
t.belongs_to :xxx, polymorphic: true, :index => false
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
@@ -31,7 +31,7 @@ end
|
|
31
31
|
|
32
32
|
class Article < ActiveRecord::Base
|
33
33
|
belongs_to :user
|
34
|
-
belongs_to :xxx, :
|
34
|
+
belongs_to :xxx, polymorphic: true
|
35
35
|
end
|
36
36
|
|
37
37
|
class Blog < ActiveRecord::Base
|
@@ -49,56 +49,56 @@ Aam.logger = nil
|
|
49
49
|
|
50
50
|
class TestAam < Test::Unit::TestCase
|
51
51
|
test "test_main" do
|
52
|
-
assert_equal <<-EOT.strip_heredoc, Aam::
|
52
|
+
assert_equal <<-EOT.strip_heredoc, Aam::Generator.new(User).generate
|
53
53
|
# == Schema Information ==
|
54
54
|
#
|
55
|
-
# User
|
55
|
+
# User (users as User)
|
56
56
|
#
|
57
|
-
#
|
58
|
-
# |
|
59
|
-
#
|
60
|
-
# | id
|
61
|
-
# | name
|
62
|
-
# | flag
|
63
|
-
#
|
57
|
+
# |------+------+------------+-------------+------+-------|
|
58
|
+
# | name | desc | type | opts | refs | index |
|
59
|
+
# |------+------+------------+-------------+------+-------|
|
60
|
+
# | id | Id | integer | NOT NULL PK | | |
|
61
|
+
# | name | Name | string(32) | | | A! |
|
62
|
+
# | flag | Flag | boolean | DEFAULT(0) | | |
|
63
|
+
# |------+------+------------+-------------+------+-------|
|
64
64
|
EOT
|
65
|
-
assert_equal <<-EOT.strip_heredoc, Aam::
|
65
|
+
assert_equal <<-EOT.strip_heredoc, Aam::Generator.new(Article).generate
|
66
66
|
# == Schema Information ==
|
67
67
|
#
|
68
|
-
# Article
|
68
|
+
# Article (articles as Article)
|
69
69
|
#
|
70
|
-
#
|
71
|
-
# |
|
72
|
-
#
|
73
|
-
# | id | Id | integer | NOT NULL PK |
|
74
|
-
# | user_id | User | integer | | => User#id
|
75
|
-
# | xxx_type | Xxx type | string | |
|
76
|
-
# | xxx_id | Xxx | integer | | => (xxx_type)#id
|
77
|
-
#
|
70
|
+
# |----------+----------+---------+-------------+----------------------------+-------|
|
71
|
+
# | name | desc | type | opts | refs | index |
|
72
|
+
# |----------+----------+---------+-------------+----------------------------+-------|
|
73
|
+
# | id | Id | integer | NOT NULL PK | | |
|
74
|
+
# | user_id | User | integer | | => User#id | |
|
75
|
+
# | xxx_type | Xxx type | string | | SpecificModel(polymorphic) | |
|
76
|
+
# | xxx_id | Xxx | integer | | => (xxx_type)#id | |
|
77
|
+
# |----------+----------+---------+-------------+----------------------------+-------|
|
78
78
|
#
|
79
|
-
#-
|
80
|
-
#
|
81
|
-
#
|
82
|
-
#
|
79
|
+
#- Remarks ----------------------------------------------------------------------
|
80
|
+
# User.has_many :articles
|
81
|
+
# [Warning: Need to add index] create_articles マイグレーションに add_index :articles, :user_id を追加してください
|
82
|
+
# [Warning: Need to add index] create_articles マイグレーションに add_index :articles, [:xxx_id, :xxx_type] を追加してください
|
83
83
|
#--------------------------------------------------------------------------------
|
84
84
|
EOT
|
85
|
-
Aam::
|
85
|
+
Aam::Generator.new(SubArticle).generate == <<-EOT.strip_heredoc
|
86
86
|
# == Schema Information ==
|
87
87
|
#
|
88
|
-
# Sub article
|
88
|
+
# Sub article (articles as SubArticle)
|
89
89
|
#
|
90
90
|
# |----------+----------+---------+-------------+--------------------------------------+-------|
|
91
|
-
# |
|
91
|
+
# | name | desc | type | opts | refs | index |
|
92
92
|
# |----------+----------+---------+-------------+--------------------------------------+-------|
|
93
93
|
# | id | Id | integer | NOT NULL PK | | |
|
94
94
|
# | user_id | User | integer | | => User#id | |
|
95
|
-
# | xxx_type | Xxx type | string | |
|
95
|
+
# | xxx_type | Xxx type | string | | SpecificModel(polymorphic) | |
|
96
96
|
# | xxx_id | Xxx | integer | | :blog => Blog#id と => (xxx_type)#id | |
|
97
97
|
# |----------+----------+---------+-------------+--------------------------------------+-------|
|
98
98
|
#
|
99
99
|
#- 備考 -------------------------------------------------------------------------
|
100
|
-
#
|
101
|
-
#
|
100
|
+
# ・[Warning: Need to add index] create_articles マイグレーションに add_index :articles, :user_id を追加してください
|
101
|
+
# ・[Warning: Need to add index] create_articles マイグレーションに add_index :articles, [:xxx_id, :xxx_type] を追加してください
|
102
102
|
#--------------------------------------------------------------------------------
|
103
103
|
EOT
|
104
104
|
end
|
@@ -122,13 +122,13 @@ EOT
|
|
122
122
|
end
|
123
123
|
|
124
124
|
test "test_foo" do
|
125
|
-
assert_equal <<-EOT.strip_heredoc, Aam::
|
125
|
+
assert_equal <<-EOT.strip_heredoc, Aam::Generator.new(Foo).generate
|
126
126
|
# == Schema Information ==
|
127
127
|
#
|
128
|
-
# Foo
|
128
|
+
# Foo (foos as Foo)
|
129
129
|
#
|
130
130
|
# |----------+----------+---------+-------------+------+-------|
|
131
|
-
# |
|
131
|
+
# | name | desc | type | opts | refs | index |
|
132
132
|
# |----------+----------+---------+-------------+------+-------|
|
133
133
|
# | id | Id | integer | NOT NULL PK | | |
|
134
134
|
# | user_id | User | integer | | | |
|
@@ -136,11 +136,11 @@ EOT
|
|
136
136
|
# | xxx_id | Xxx | integer | | | |
|
137
137
|
# |----------+----------+---------+-------------+------+-------|
|
138
138
|
#
|
139
|
-
#-
|
140
|
-
#
|
141
|
-
#
|
142
|
-
#
|
143
|
-
#
|
139
|
+
#- Remarks ----------------------------------------------------------------------
|
140
|
+
# [Warning: Need to add index] create_foos マイグレーションに add_index :foos, :user_id を追加してください
|
141
|
+
# [Warning: Need to add index] create_foos マイグレーションに add_index :foos, [:xxx_id, :xxx_type] を追加してください
|
142
|
+
# [Warning: Need to add relation] Foo モデルに belongs_to :user を追加してください
|
143
|
+
# [Warning: Need to add relation] Foo モデルに belongs_to :xxx, polymorphic: true を追加してください
|
144
144
|
#--------------------------------------------------------------------------------
|
145
145
|
EOT
|
146
146
|
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,29 +1,28 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aam
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- akicho8
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: bundler
|
15
14
|
requirement: !ruby/object:Gem::Requirement
|
16
15
|
requirements:
|
17
|
-
- - "
|
16
|
+
- - ">="
|
18
17
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
18
|
+
version: '0'
|
20
19
|
type: :development
|
21
20
|
prerelease: false
|
22
21
|
version_requirements: !ruby/object:Gem::Requirement
|
23
22
|
requirements:
|
24
|
-
- - "
|
23
|
+
- - ">="
|
25
24
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
25
|
+
version: '0'
|
27
26
|
- !ruby/object:Gem::Dependency
|
28
27
|
name: rake
|
29
28
|
requirement: !ruby/object:Gem::Requirement
|
@@ -130,7 +129,6 @@ extensions: []
|
|
130
129
|
extra_rdoc_files: []
|
131
130
|
files:
|
132
131
|
- ".gitignore"
|
133
|
-
- ".travis.yml"
|
134
132
|
- Gemfile
|
135
133
|
- LICENSE.txt
|
136
134
|
- README.org
|
@@ -139,8 +137,8 @@ files:
|
|
139
137
|
- examples/0100_example.rb
|
140
138
|
- lib/aam.rb
|
141
139
|
- lib/aam/annotation.rb
|
140
|
+
- lib/aam/generator.rb
|
142
141
|
- lib/aam/railtie.rb
|
143
|
-
- lib/aam/schema_info_generator.rb
|
144
142
|
- lib/aam/tasks/aam.rake
|
145
143
|
- lib/aam/version.rb
|
146
144
|
- test/test_aam.rb
|
@@ -149,7 +147,6 @@ homepage: ''
|
|
149
147
|
licenses:
|
150
148
|
- MIT
|
151
149
|
metadata: {}
|
152
|
-
post_install_message:
|
153
150
|
rdoc_options: []
|
154
151
|
require_paths:
|
155
152
|
- lib
|
@@ -164,9 +161,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
164
161
|
- !ruby/object:Gem::Version
|
165
162
|
version: '0'
|
166
163
|
requirements: []
|
167
|
-
|
168
|
-
rubygems_version: 2.7.6
|
169
|
-
signing_key:
|
164
|
+
rubygems_version: 3.6.8
|
170
165
|
specification_version: 4
|
171
166
|
summary: Advanced Annotate Models
|
172
167
|
test_files:
|
data/.travis.yml
DELETED