aam 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,19 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ require "rails"
4
+
5
+ desc "#{Rails.root} 以下のファイルに対してスキーマ情報を関連するファイルに書き込む"
6
+ task :aam => "aam:app"
7
+
8
+ namespace :aam do
9
+ task :app => :environment do
10
+ require "aam"
11
+ Aam::Annotation.run
12
+ end
13
+
14
+ desc "#{Rails.root}/vendor/plugins 以下のファイルに対してスキーマ情報を関連するファイルに書き込む"
15
+ task :plugins => :environment do
16
+ require "aam"
17
+ Aam::Annotation.run(:root_dir => Rails.root.join("vendor/plugins"))
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ module Aam
2
+ VERSION = "0.0.5"
3
+ end
@@ -0,0 +1,147 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'test_helper'
3
+
4
+ ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")
5
+ ActiveRecord::Schema.define do
6
+ suppress_messages do
7
+ create_table(:users) do |t|
8
+ t.string :name, :limit => 32
9
+ t.boolean :flag, :default => false
10
+ end
11
+ add_index :users, :name, :unique => true
12
+
13
+ create_table(:articles) do |t|
14
+ t.belongs_to :user, :index => false
15
+ t.belongs_to :xxx, :polymorphic => true, :index => false
16
+ end
17
+ create_table(:blogs) do |t|
18
+ t.string :name
19
+ end
20
+ create_table(:foos) do |t|
21
+ t.belongs_to :user, :index => false
22
+ t.belongs_to :xxx, :polymorphic => true, :index => false
23
+ end
24
+ end
25
+ end
26
+
27
+ class User < ActiveRecord::Base
28
+ has_many :articles
29
+ has_one :article, :as => :xxx
30
+ end
31
+
32
+ class Article < ActiveRecord::Base
33
+ belongs_to :user
34
+ belongs_to :xxx, :polymorphic => true
35
+ end
36
+
37
+ class Blog < ActiveRecord::Base
38
+ has_many :sub_articles, :foreign_key => :xxx_id
39
+ end
40
+
41
+ class SubArticle < Article
42
+ belongs_to :blog, :class_name => "Blog", :foreign_key => :xxx_id
43
+ end
44
+
45
+ class Foo < ActiveRecord::Base
46
+ end
47
+
48
+ Aam.logger = nil
49
+
50
+ class TestAam < Test::Unit::TestCase
51
+ test "test_main" do
52
+ assert_equal <<-EOT.strip_heredoc, Aam::SchemaInfoGenerator.new(User).generate
53
+ # == Schema Information ==
54
+ #
55
+ # Userテーブル (users as User)
56
+ #
57
+ # |----------+------+------------+-------------+------+-------|
58
+ # | カラム名 | 意味 | タイプ | 属性 | 参照 | INDEX |
59
+ # |----------+------+------------+-------------+------+-------|
60
+ # | id | Id | integer | NOT NULL PK | | |
61
+ # | name | Name | string(32) | | | A! |
62
+ # | flag | Flag | boolean | DEFAULT(f) | | |
63
+ # |----------+------+------------+-------------+------+-------|
64
+ EOT
65
+ assert_equal <<-EOT.strip_heredoc, Aam::SchemaInfoGenerator.new(Article).generate
66
+ # == Schema Information ==
67
+ #
68
+ # Articleテーブル (articles as Article)
69
+ #
70
+ # |----------+----------+---------+-------------+-----------------------+-------|
71
+ # | カラム名 | 意味 | タイプ | 属性 | 参照 | INDEX |
72
+ # |----------+----------+---------+-------------+-----------------------+-------|
73
+ # | id | Id | integer | NOT NULL PK | | |
74
+ # | user_id | User | integer | | => User#id | |
75
+ # | xxx_type | Xxx type | string | | モデル名(polymorphic) | |
76
+ # | xxx_id | Xxx | integer | | => (xxx_type)#id | |
77
+ # |----------+----------+---------+-------------+-----------------------+-------|
78
+ #
79
+ #- 備考 -------------------------------------------------------------------------
80
+ # ・【警告:インデックス欠如】create_articles マイグレーションに add_index :articles, :user_id を追加してください
81
+ # ・Article モデルは User モデルから has_many :articles されています。
82
+ # ・【警告:インデックス欠如】create_articles マイグレーションに add_index :articles, [:xxx_id, :xxx_type] を追加してください
83
+ #--------------------------------------------------------------------------------
84
+ EOT
85
+ Aam::SchemaInfoGenerator.new(SubArticle).generate == <<-EOT.strip_heredoc
86
+ # == Schema Information ==
87
+ #
88
+ # Sub articleテーブル (articles as SubArticle)
89
+ #
90
+ # |----------+----------+---------+-------------+--------------------------------------+-------|
91
+ # | カラム名 | 意味 | タイプ | 属性 | 参照 | INDEX |
92
+ # |----------+----------+---------+-------------+--------------------------------------+-------|
93
+ # | id | Id | integer | NOT NULL PK | | |
94
+ # | user_id | User | integer | | => User#id | |
95
+ # | xxx_type | Xxx type | string | | モデル名(polymorphic) | |
96
+ # | xxx_id | Xxx | integer | | :blog => Blog#id と => (xxx_type)#id | |
97
+ # |----------+----------+---------+-------------+--------------------------------------+-------|
98
+ #
99
+ #- 備考 -------------------------------------------------------------------------
100
+ # ・【警告:インデックス欠如】create_articles マイグレーションに add_index :articles, :user_id を追加してください
101
+ # ・【警告:インデックス欠如】create_articles マイグレーションに add_index :articles, [:xxx_id, :xxx_type] を追加してください
102
+ #--------------------------------------------------------------------------------
103
+ EOT
104
+ end
105
+
106
+ test "test_blog_sub_articles" do
107
+ b = Blog.new
108
+ b.sub_articles.build
109
+ b.save!
110
+
111
+ b.reload
112
+ # p b.sub_articles
113
+ end
114
+
115
+ test "test_blog_sub_articles2" do
116
+ b = Blog.new
117
+ b.sub_articles.build
118
+ b.save!
119
+
120
+ b.reload
121
+ # p b.sub_articles
122
+ end
123
+
124
+ test "test_foo" do
125
+ assert_equal <<-EOT.strip_heredoc, Aam::SchemaInfoGenerator.new(Foo).generate
126
+ # == Schema Information ==
127
+ #
128
+ # Fooテーブル (foos as Foo)
129
+ #
130
+ # |----------+----------+---------+-------------+------+-------|
131
+ # | カラム名 | 意味 | タイプ | 属性 | 参照 | INDEX |
132
+ # |----------+----------+---------+-------------+------+-------|
133
+ # | id | Id | integer | NOT NULL PK | | |
134
+ # | user_id | User | integer | | | |
135
+ # | xxx_type | Xxx type | string | | | |
136
+ # | xxx_id | Xxx | integer | | | |
137
+ # |----------+----------+---------+-------------+------+-------|
138
+ #
139
+ #- 備考 -------------------------------------------------------------------------
140
+ # ・【警告:インデックス欠如】create_foos マイグレーションに add_index :foos, :user_id を追加してください
141
+ # ・【警告】Foo モデルに belongs_to :user を追加してください
142
+ # ・【警告:インデックス欠如】create_foos マイグレーションに add_index :foos, [:xxx_id, :xxx_type] を追加してください
143
+ # ・【警告】Foo モデルに belongs_to :xxx, :polymorphic => true を追加してください
144
+ #--------------------------------------------------------------------------------
145
+ EOT
146
+ end
147
+ end
@@ -0,0 +1,3 @@
1
+ require "test/unit"
2
+ $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
3
+ require "aam"
metadata ADDED
@@ -0,0 +1,175 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: aam
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.5
5
+ platform: ruby
6
+ authors:
7
+ - akicho8
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-06-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: test-unit
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: sqlite3
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rails
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: activerecord
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: activesupport
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: org_tp
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: Index reference to Japanese correspondence relation annotate_models
126
+ email:
127
+ - akicho8@gmail.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - ".travis.yml"
134
+ - Gemfile
135
+ - LICENSE.txt
136
+ - README.org
137
+ - Rakefile
138
+ - aam.gemspec
139
+ - examples/0100_example.rb
140
+ - experiment/000_example.rb
141
+ - lib/aam.rb
142
+ - lib/aam/annotation.rb
143
+ - lib/aam/railtie.rb
144
+ - lib/aam/schema_info_generator.rb
145
+ - lib/aam/tasks/aam.rake
146
+ - lib/aam/version.rb
147
+ - test/test_aam.rb
148
+ - test/test_helper.rb
149
+ homepage: ''
150
+ licenses:
151
+ - MIT
152
+ metadata: {}
153
+ post_install_message:
154
+ rdoc_options: []
155
+ require_paths:
156
+ - lib
157
+ required_ruby_version: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
162
+ required_rubygems_version: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ requirements: []
168
+ rubyforge_project:
169
+ rubygems_version: 2.7.6
170
+ signing_key:
171
+ specification_version: 4
172
+ summary: Advanced Annotate Models
173
+ test_files:
174
+ - test/test_aam.rb
175
+ - test/test_helper.rb