roomer 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/.autotest +17 -0
- data/.gitignore +9 -0
- data/.rvmrc +2 -0
- data/.travis.yml +2 -0
- data/Gemfile +31 -0
- data/MIT-LICENSE +20 -0
- data/README.md +116 -0
- data/Rakefile +16 -0
- data/TODO.md +10 -0
- data/doc/ActiveRecord/Base.html +328 -0
- data/doc/ApplicationController.html +116 -0
- data/doc/Roomer/Engine.html +116 -0
- data/doc/Roomer/Generators/InstallGenerator.html +419 -0
- data/doc/Roomer/Generators/SetupGenerator.html +209 -0
- data/doc/Roomer/Generators.html +108 -0
- data/doc/Roomer/Tools.html +702 -0
- data/doc/Roomer/VERSION.html +149 -0
- data/doc/Roomer.html +533 -0
- data/doc/RoomerCreate.html +121 -0
- data/doc/_index.html +232 -0
- data/doc/class_list.html +47 -0
- data/doc/css/common.css +1 -0
- data/doc/css/full_list.css +53 -0
- data/doc/css/style.css +320 -0
- data/doc/file.README.html +146 -0
- data/doc/file_list.html +49 -0
- data/doc/frames.html +13 -0
- data/doc/index.html +146 -0
- data/doc/js/app.js +205 -0
- data/doc/js/full_list.js +150 -0
- data/doc/js/jquery.js +16 -0
- data/doc/method_list.html +182 -0
- data/doc/top-level-namespace.html +105 -0
- data/lib/generators/roomer/install/install_generator.rb +39 -0
- data/lib/generators/roomer/install/templates/README +15 -0
- data/lib/generators/roomer/install/templates/roomer.rb +68 -0
- data/lib/generators/roomer/migration/migration_generator.rb +35 -0
- data/lib/generators/roomer/migration/templates/migration.rb +17 -0
- data/lib/generators/roomer/model/model_generator.rb +45 -0
- data/lib/generators/roomer/model/templates/migration.rb +16 -0
- data/lib/generators/roomer/setup/setup_generator.rb +38 -0
- data/lib/generators/roomer/setup/templates/global_migration.rb +20 -0
- data/lib/roomer/extensions/controller.rb +36 -0
- data/lib/roomer/extensions/model.rb +72 -0
- data/lib/roomer/helpers/generator_helper.rb +30 -0
- data/lib/roomer/helpers/migration_helper.rb +7 -0
- data/lib/roomer/helpers/postgres_helper.rb +75 -0
- data/lib/roomer/rails.rb +24 -0
- data/lib/roomer/schema.rb +63 -0
- data/lib/roomer/schema_dumper.rb +36 -0
- data/lib/roomer/tasks/migrate.rake +85 -0
- data/lib/roomer/utils.rb +68 -0
- data/lib/roomer/version.rb +14 -0
- data/lib/roomer.rb +125 -0
- data/roomer.gemspec +22 -0
- data/test/config.rb +3 -0
- data/test/config.yml +7 -0
- data/test/generators/install_generator_test.rb +13 -0
- data/test/generators/migration_generator_test.rb +33 -0
- data/test/generators/model_generator_test.rb +25 -0
- data/test/generators/setup_generator_test.rb +25 -0
- data/test/rails_app/app/controllers/application_controller.rb +3 -0
- data/test/rails_app/app/helpers/application_helper.rb +2 -0
- data/test/rails_app/app/models/tenant.rb +12 -0
- data/test/rails_app/app/views/layouts/application.html.erb +14 -0
- data/test/rails_app/config/application.rb +50 -0
- data/test/rails_app/config/boot.rb +6 -0
- data/test/rails_app/config/database.yml +2 -0
- data/test/rails_app/config/environment.rb +5 -0
- data/test/rails_app/config/environments/development.rb +26 -0
- data/test/rails_app/config/environments/production.rb +49 -0
- data/test/rails_app/config/environments/test.rb +35 -0
- data/test/rails_app/config/initializers/backtrace_silencers.rb +7 -0
- data/test/rails_app/config/initializers/inflections.rb +10 -0
- data/test/rails_app/config/initializers/mime_types.rb +5 -0
- data/test/rails_app/config/initializers/roomer.rb +68 -0
- data/test/rails_app/config/initializers/secret_token.rb +7 -0
- data/test/rails_app/config/initializers/session_store.rb +8 -0
- data/test/rails_app/config/locales/en.yml +5 -0
- data/test/rails_app/config/routes.rb +58 -0
- data/test/rails_app/config.ru +4 -0
- data/test/rails_app/db/migrate/global/20110825231409_roomer_create_tenants.rb +20 -0
- data/test/rails_app/db/seeds.rb +7 -0
- data/test/rails_app/lib/tasks/.gitkeep +0 -0
- data/test/rails_app/public/404.html +26 -0
- data/test/rails_app/public/422.html +26 -0
- data/test/rails_app/public/500.html +26 -0
- data/test/rails_app/public/favicon.ico +0 -0
- data/test/rails_app/public/images/rails.png +0 -0
- data/test/rails_app/public/index.html +239 -0
- data/test/rails_app/public/javascripts/application.js +2 -0
- data/test/rails_app/public/javascripts/controls.js +965 -0
- data/test/rails_app/public/javascripts/dragdrop.js +974 -0
- data/test/rails_app/public/javascripts/effects.js +1123 -0
- data/test/rails_app/public/javascripts/prototype.js +6001 -0
- data/test/rails_app/public/javascripts/rails.js +191 -0
- data/test/rails_app/public/robots.txt +5 -0
- data/test/rails_app/public/stylesheets/.gitkeep +0 -0
- data/test/roomer/helpers/postgres_helper_test.rb +62 -0
- data/test/roomer/roomer_test.rb +37 -0
- data/test/test_helper.rb +23 -0
- metadata +228 -0
@@ -0,0 +1,182 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3
|
+
<html>
|
4
|
+
<head>
|
5
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
6
|
+
|
7
|
+
<link rel="stylesheet" href="css/full_list.css" type="text/css" media="screen" charset="utf-8" />
|
8
|
+
|
9
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" media="screen" charset="utf-8" />
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
14
|
+
|
15
|
+
<script type="text/javascript" charset="utf-8" src="js/full_list.js"></script>
|
16
|
+
|
17
|
+
|
18
|
+
<base id="base_target" target="_parent" />
|
19
|
+
</head>
|
20
|
+
<body>
|
21
|
+
<script type="text/javascript" charset="utf-8">
|
22
|
+
if (window.top.frames.main) {
|
23
|
+
document.getElementById('base_target').target = 'main';
|
24
|
+
document.body.className = 'frames';
|
25
|
+
}
|
26
|
+
</script>
|
27
|
+
<div id="content">
|
28
|
+
<h1 id="full_list_header">Method List</h1>
|
29
|
+
<div id="nav">
|
30
|
+
|
31
|
+
<a target="_self" href="class_list.html">Classes</a>
|
32
|
+
|
33
|
+
<a target="_self" href="method_list.html">Methods</a>
|
34
|
+
|
35
|
+
<a target="_self" href="file_list.html">Files</a>
|
36
|
+
|
37
|
+
</div>
|
38
|
+
<div id="search">Search: <input type="text" /></div>
|
39
|
+
|
40
|
+
<ul id="full_list" class="methods">
|
41
|
+
|
42
|
+
|
43
|
+
<li class="r1 ">
|
44
|
+
<span class='object_link'><a href="Roomer/Generators/InstallGenerator.html#copy_initializer-instance_method" title="Roomer::Generators::InstallGenerator#copy_initializer (method)">#copy_initializer</a></span>
|
45
|
+
|
46
|
+
<small>Roomer::Generators::InstallGenerator</small>
|
47
|
+
|
48
|
+
</li>
|
49
|
+
|
50
|
+
|
51
|
+
<li class="r2 ">
|
52
|
+
<span class='object_link'><a href="Roomer/Generators/SetupGenerator.html#create_migration_file-instance_method" title="Roomer::Generators::SetupGenerator#create_migration_file (method)">#create_migration_file</a></span>
|
53
|
+
|
54
|
+
<small>Roomer::Generators::SetupGenerator</small>
|
55
|
+
|
56
|
+
</li>
|
57
|
+
|
58
|
+
|
59
|
+
<li class="r1 ">
|
60
|
+
<span class='object_link'><a href="Roomer/Tools.html#create_schema-class_method" title="Roomer::Tools.create_schema (method)">create_schema</a></span>
|
61
|
+
|
62
|
+
<small>Roomer::Tools</small>
|
63
|
+
|
64
|
+
</li>
|
65
|
+
|
66
|
+
|
67
|
+
<li class="r2 ">
|
68
|
+
<span class='object_link'><a href="Roomer/Tools.html#drop_schema-class_method" title="Roomer::Tools.drop_schema (method)">drop_schema</a></span>
|
69
|
+
|
70
|
+
<small>Roomer::Tools</small>
|
71
|
+
|
72
|
+
</li>
|
73
|
+
|
74
|
+
|
75
|
+
<li class="r1 ">
|
76
|
+
<span class='object_link'><a href="Roomer/Tools.html#ensure_prefix-class_method" title="Roomer::Tools.ensure_prefix (method)">ensure_prefix</a></span>
|
77
|
+
|
78
|
+
<small>Roomer::Tools</small>
|
79
|
+
|
80
|
+
</li>
|
81
|
+
|
82
|
+
|
83
|
+
<li class="r2 ">
|
84
|
+
<span class='object_link'><a href="Roomer/Tools.html#ensure_schema_migrations-class_method" title="Roomer::Tools.ensure_schema_migrations (method)">ensure_schema_migrations</a></span>
|
85
|
+
|
86
|
+
<small>Roomer::Tools</small>
|
87
|
+
|
88
|
+
</li>
|
89
|
+
|
90
|
+
|
91
|
+
<li class="r1 ">
|
92
|
+
<span class='object_link'><a href="Roomer/Tools.html#ensuring_schema-class_method" title="Roomer::Tools.ensuring_schema (method)">ensuring_schema</a></span>
|
93
|
+
|
94
|
+
<small>Roomer::Tools</small>
|
95
|
+
|
96
|
+
</li>
|
97
|
+
|
98
|
+
|
99
|
+
<li class="r2 ">
|
100
|
+
<span class='object_link'><a href="Roomer.html#full_shared_shema_migration_path-class_method" title="Roomer.full_shared_shema_migration_path (method)">full_shared_shema_migration_path</a></span>
|
101
|
+
|
102
|
+
<small>Roomer</small>
|
103
|
+
|
104
|
+
</li>
|
105
|
+
|
106
|
+
|
107
|
+
<li class="r1 ">
|
108
|
+
<span class='object_link'><a href="Roomer.html#full_tenants_table_name-class_method" title="Roomer.full_tenants_table_name (method)">full_tenants_table_name</a></span>
|
109
|
+
|
110
|
+
<small>Roomer</small>
|
111
|
+
|
112
|
+
</li>
|
113
|
+
|
114
|
+
|
115
|
+
<li class="r2 ">
|
116
|
+
<span class='object_link'><a href="Roomer.html#migrations_directory-class_method" title="Roomer.migrations_directory (method)">migrations_directory</a></span>
|
117
|
+
|
118
|
+
<small>Roomer</small>
|
119
|
+
|
120
|
+
</li>
|
121
|
+
|
122
|
+
|
123
|
+
<li class="r1 ">
|
124
|
+
<span class='object_link'><a href="ActiveRecord/Base.html#roomer-class_method" title="ActiveRecord::Base.roomer (method)">roomer</a></span>
|
125
|
+
|
126
|
+
<small>ActiveRecord::Base</small>
|
127
|
+
|
128
|
+
</li>
|
129
|
+
|
130
|
+
|
131
|
+
<li class="r2 ">
|
132
|
+
<span class='object_link'><a href="Roomer/Tools.html#schemas-class_method" title="Roomer::Tools.schemas (method)">schemas</a></span>
|
133
|
+
|
134
|
+
<small>Roomer::Tools</small>
|
135
|
+
|
136
|
+
</li>
|
137
|
+
|
138
|
+
|
139
|
+
<li class="r1 ">
|
140
|
+
<span class='object_link'><a href="Roomer.html#setup-class_method" title="Roomer.setup (method)">setup</a></span>
|
141
|
+
|
142
|
+
<small>Roomer</small>
|
143
|
+
|
144
|
+
</li>
|
145
|
+
|
146
|
+
|
147
|
+
<li class="r2 ">
|
148
|
+
<span class='object_link'><a href="Roomer/Generators/InstallGenerator.html#shared_schema_name-instance_method" title="Roomer::Generators::InstallGenerator#shared_schema_name (method)">#shared_schema_name</a></span>
|
149
|
+
|
150
|
+
<small>Roomer::Generators::InstallGenerator</small>
|
151
|
+
|
152
|
+
</li>
|
153
|
+
|
154
|
+
|
155
|
+
<li class="r1 ">
|
156
|
+
<span class='object_link'><a href="Roomer/Generators/InstallGenerator.html#show_readme-instance_method" title="Roomer::Generators::InstallGenerator#show_readme (method)">#show_readme</a></span>
|
157
|
+
|
158
|
+
<small>Roomer::Generators::InstallGenerator</small>
|
159
|
+
|
160
|
+
</li>
|
161
|
+
|
162
|
+
|
163
|
+
<li class="r2 ">
|
164
|
+
<span class='object_link'><a href="ActiveRecord/Base.html#table_name_prefix-class_method" title="ActiveRecord::Base.table_name_prefix (method)">table_name_prefix</a></span>
|
165
|
+
|
166
|
+
<small>ActiveRecord::Base</small>
|
167
|
+
|
168
|
+
</li>
|
169
|
+
|
170
|
+
|
171
|
+
<li class="r1 ">
|
172
|
+
<span class='object_link'><a href="Roomer/Generators/InstallGenerator.html#tenants_table-instance_method" title="Roomer::Generators::InstallGenerator#tenants_table (method)">#tenants_table</a></span>
|
173
|
+
|
174
|
+
<small>Roomer::Generators::InstallGenerator</small>
|
175
|
+
|
176
|
+
</li>
|
177
|
+
|
178
|
+
|
179
|
+
</ul>
|
180
|
+
</div>
|
181
|
+
</body>
|
182
|
+
</html>
|
@@ -0,0 +1,105 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
2
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
3
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
4
|
+
<head>
|
5
|
+
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
6
|
+
<title>
|
7
|
+
Top Level Namespace
|
8
|
+
|
9
|
+
— Documentation by YARD 0.7.2
|
10
|
+
|
11
|
+
</title>
|
12
|
+
|
13
|
+
<link rel="stylesheet" href="css/style.css" type="text/css" media="screen" charset="utf-8" />
|
14
|
+
|
15
|
+
<link rel="stylesheet" href="css/common.css" type="text/css" media="screen" charset="utf-8" />
|
16
|
+
|
17
|
+
<script type="text/javascript" charset="utf-8">
|
18
|
+
relpath = '';
|
19
|
+
if (relpath != '') relpath += '/';
|
20
|
+
</script>
|
21
|
+
|
22
|
+
<script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
|
23
|
+
|
24
|
+
<script type="text/javascript" charset="utf-8" src="js/app.js"></script>
|
25
|
+
|
26
|
+
|
27
|
+
</head>
|
28
|
+
<body>
|
29
|
+
<script type="text/javascript" charset="utf-8">
|
30
|
+
if (window.top.frames.main) document.body.className = 'frames';
|
31
|
+
</script>
|
32
|
+
|
33
|
+
<div id="header">
|
34
|
+
<div id="menu">
|
35
|
+
|
36
|
+
<a href="_index.html">Index</a> »
|
37
|
+
|
38
|
+
|
39
|
+
<span class="title">Top Level Namespace</span>
|
40
|
+
|
41
|
+
|
42
|
+
<div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div>
|
43
|
+
</div>
|
44
|
+
|
45
|
+
<div id="search">
|
46
|
+
|
47
|
+
<a id="class_list_link" href="#">Class List</a>
|
48
|
+
|
49
|
+
<a id="method_list_link" href="#">Method List</a>
|
50
|
+
|
51
|
+
<a id="file_list_link" href="#">File List</a>
|
52
|
+
|
53
|
+
</div>
|
54
|
+
<div class="clear"></div>
|
55
|
+
</div>
|
56
|
+
|
57
|
+
<iframe id="search_frame"></iframe>
|
58
|
+
|
59
|
+
<div id="content"><h1>Top Level Namespace
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
</h1>
|
64
|
+
|
65
|
+
<dl class="box">
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
</dl>
|
75
|
+
<div class="clear"></div>
|
76
|
+
|
77
|
+
<h2>Defined Under Namespace</h2>
|
78
|
+
<p class="children">
|
79
|
+
|
80
|
+
|
81
|
+
<strong class="modules">Modules:</strong> <span class='object_link'><a href="Roomer.html" title="Roomer (module)">Roomer</a></span>
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
<strong class="classes">Classes:</strong> <span class='object_link'><a href="ApplicationController.html" title="ApplicationController (class)">ApplicationController</a></span>, <span class='object_link'><a href="RoomerCreate.html" title="RoomerCreate (class)">RoomerCreate</a></span>
|
86
|
+
|
87
|
+
|
88
|
+
</p>
|
89
|
+
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
|
96
|
+
</div>
|
97
|
+
|
98
|
+
<div id="footer">
|
99
|
+
Generated on Fri Aug 12 10:39:13 2011 by
|
100
|
+
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
101
|
+
0.7.2 (ruby-1.8.7).
|
102
|
+
</div>
|
103
|
+
|
104
|
+
</body>
|
105
|
+
</html>
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Roomer
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
|
5
|
+
source_root File.expand_path("../templates", __FILE__)
|
6
|
+
|
7
|
+
class_option :tenants_table, :aliases => "-t", :default => "tenants",
|
8
|
+
:desc => "Name of tenant tables"
|
9
|
+
|
10
|
+
class_option :shared_schema_name, :aliases => "-s", :default => "global",
|
11
|
+
:desc => "Name of shared schema"
|
12
|
+
|
13
|
+
desc "Creates a Roomer initializer for your application and generates the necessary migration"
|
14
|
+
|
15
|
+
# Reads the tenants-table option and assigns it to Roomer.tenants_table config parameter
|
16
|
+
# @return [Symbol] tenants table name
|
17
|
+
def tenants_table
|
18
|
+
Roomer.tenants_table ||= options[:tenants_table].to_s
|
19
|
+
end
|
20
|
+
|
21
|
+
# Reads the shared-schema-name and assigns it to Roomer.shared_schema_name
|
22
|
+
# @return [Symbol] shared schema name
|
23
|
+
def shared_schema_name
|
24
|
+
Roomer.shared_schema_name ||= options[:shared_schema_name].to_s
|
25
|
+
end
|
26
|
+
|
27
|
+
# Generates the Initializer under config/initializers/roomer.rb
|
28
|
+
def copy_initializer
|
29
|
+
template "roomer.rb", "config/initializers/roomer.rb"
|
30
|
+
end
|
31
|
+
|
32
|
+
# Displays the instructions for setting up Roomer
|
33
|
+
def show_readme
|
34
|
+
readme "README" if behavior == :invoke
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
===============================================================================
|
2
|
+
Hooray! Roomer is successfully installed
|
3
|
+
|
4
|
+
Step 1: Initializer is under config/initializers/roomer.rb. This describes ALL
|
5
|
+
configuration options and you MUST take a look at it.
|
6
|
+
|
7
|
+
Step 2: Setup roomer, run:
|
8
|
+
|
9
|
+
rails generate roomer:setup
|
10
|
+
|
11
|
+
Step 3: Run shared migrations, this will create the tenants table in the shared schema
|
12
|
+
|
13
|
+
rake roomer:shared:migrate
|
14
|
+
|
15
|
+
===============================================================================
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
Roomer.setup do |config|
|
3
|
+
|
4
|
+
# ==> URL Routing Strategy
|
5
|
+
# Configure the URL routing strategy. Roomer currently supports two routing strategies
|
6
|
+
# :domain : Using domain name to identify the tenant. This could include a subdomain
|
7
|
+
# e.g. http://mytenant.myapp.com - If you tenant has a subdomain
|
8
|
+
# under your domain
|
9
|
+
# http://mytenant.com - If the tenant choose to use their
|
10
|
+
# own top level domain name
|
11
|
+
# http://myapp.mytenant.com - If the tenant chooses to use their
|
12
|
+
# own subdomain under thier TLD
|
13
|
+
# :path : Identifying the tenant by the path
|
14
|
+
# e.g. http://yourapp.com/tenant
|
15
|
+
# Default is :domain
|
16
|
+
# config.url_routing_strategy = :domain
|
17
|
+
|
18
|
+
# ==> Data Settings (Advanced)
|
19
|
+
# IMPORTANT: Modifying these settings after you ran "rails generate roomer:setup"
|
20
|
+
# will require you to make manual changes in the database. Proceed with caution.
|
21
|
+
|
22
|
+
# Configure the name of the shared schema, this is where all the shared
|
23
|
+
# tables are be present. The default is :global
|
24
|
+
# config.shared_schema_name = :shared_schema_name
|
25
|
+
|
26
|
+
# Configure the name of the table where the tenants are stored, this table must
|
27
|
+
# contain two required columns configured under:
|
28
|
+
# config.tenant_url_identifier_column
|
29
|
+
# config.tenant_schema_name_column
|
30
|
+
# The default value is :tenants
|
31
|
+
# config.tenants_table = :tenants
|
32
|
+
|
33
|
+
# Configure the column name that strores the schema name in the tenants tables.
|
34
|
+
# The default value is :schema_name
|
35
|
+
# config.tenant_schema_name_column = :schema_name
|
36
|
+
|
37
|
+
# Configure the column name that strores the url identfier in the tenants tables.
|
38
|
+
# A url idenfier is a unique value that identifies the tenant from the URL.
|
39
|
+
# For e.g: if you use subdomains and the url is http://mytenant.myapp.com,
|
40
|
+
# the url identifier would "mytenant"
|
41
|
+
# The default value is :url_identifier
|
42
|
+
# config.tenant_url_identifier_column = :url_identifier
|
43
|
+
|
44
|
+
# Configure the schema seperator. This is used when generating the table name.
|
45
|
+
# The default is set to ".". for e.g., tenant's table by default will be global.tenants
|
46
|
+
# config.schema_seperator = "."
|
47
|
+
|
48
|
+
# Use Tentant migrations directory?
|
49
|
+
# Default is set to false
|
50
|
+
# config.use_tenanted_migrations_directory = false
|
51
|
+
|
52
|
+
# Directory where shared migrations are stored. Please make
|
53
|
+
# sure your migrations are present in this directory.
|
54
|
+
config.shared_migrations_directory = "#{Roomer.shared_migrations_directory}"
|
55
|
+
|
56
|
+
# Directory where tenanted migrations are stored. Please make
|
57
|
+
# sure your migrations are present in this directory.
|
58
|
+
config.tenanted_migrations_directory = "#{Roomer.tenanted_migrations_directory}"
|
59
|
+
|
60
|
+
# Directory where schema files will be stored.
|
61
|
+
# config.schemas_directory = File.join(Rails.root, "db", "schemas")
|
62
|
+
|
63
|
+
# Filename to use for tenanted schema
|
64
|
+
# config.tenanted_schema_filename = "tenanted_schema.rb"
|
65
|
+
|
66
|
+
# Filename to use for shared schema
|
67
|
+
# config.shared_schema_filename = "shared_schema.rb"
|
68
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'active_record/migration'
|
2
|
+
require 'rails/generators/active_record'
|
3
|
+
module Roomer
|
4
|
+
module Generators
|
5
|
+
class MigrationGenerator < Rails::Generators::NamedBase
|
6
|
+
include Rails::Generators::Migration
|
7
|
+
extend ActiveRecord::Generators::Migration
|
8
|
+
include Roomer::Helpers::GeneratorHelper
|
9
|
+
|
10
|
+
source_root File.expand_path("../templates", __FILE__)
|
11
|
+
|
12
|
+
argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
|
13
|
+
|
14
|
+
class_option :shared, :type => :boolean, :default => false,
|
15
|
+
:aliases => "-s", :desc => "shared?"
|
16
|
+
|
17
|
+
# Generates the migration
|
18
|
+
def create_migration_file
|
19
|
+
set_local_assigns!
|
20
|
+
migration_template "migration.rb", "#{migration_dir}/roomer_#{file_name}"
|
21
|
+
end
|
22
|
+
|
23
|
+
protected
|
24
|
+
attr_reader :migration_action
|
25
|
+
|
26
|
+
def set_local_assigns!
|
27
|
+
if file_name =~ /^(add|remove)_.*_(?:to|from)_(.*)/
|
28
|
+
@migration_action = $1
|
29
|
+
@table_name = $2.pluralize
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class <%= migration_class_name %> < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
<% attributes.each do |attribute| -%>
|
4
|
+
<%- if migration_action -%>
|
5
|
+
<%= migration_action %>_column :<%= table_name %>, :<%= attribute.name %><% if migration_action == 'add' %>, :<%= attribute.type %><% end %>
|
6
|
+
<%- end -%>
|
7
|
+
<%- end -%>
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.down
|
11
|
+
<% attributes.reverse.each do |attribute| -%>
|
12
|
+
<%- if migration_action -%>
|
13
|
+
<%= migration_action == 'add' ? 'remove' : 'add' %>_column :<%= table_name %>, :<%= attribute.name %><% if migration_action == 'remove' %>, :<%= attribute.type %><% end %>
|
14
|
+
<%- end -%>
|
15
|
+
<%- end -%>
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'rails/generators/active_record'
|
2
|
+
module Roomer
|
3
|
+
module Generators
|
4
|
+
class ModelGenerator < Rails::Generators::NamedBase
|
5
|
+
include Rails::Generators::Migration
|
6
|
+
extend ActiveRecord::Generators::Migration
|
7
|
+
include Roomer::Helpers::GeneratorHelper
|
8
|
+
|
9
|
+
source_root File.expand_path("../templates", __FILE__)
|
10
|
+
|
11
|
+
argument :attributes, :type => :array, :default => [],
|
12
|
+
:banner => "field:type field:type"
|
13
|
+
|
14
|
+
class_option :shared, :type => :boolean, :default => false,
|
15
|
+
:aliases => "-s", :desc => "shared?"
|
16
|
+
|
17
|
+
# Generates the active record model
|
18
|
+
# without the migration
|
19
|
+
def generate_model
|
20
|
+
invoke "active_record:model", [name], :migration => false unless model_exists? && behavior == :invoke
|
21
|
+
end
|
22
|
+
|
23
|
+
# Injects the roomer method to the class
|
24
|
+
# Example:
|
25
|
+
# rails generate roomer:model person --shared # will Generate
|
26
|
+
# class Person < ActiveRecord::Base
|
27
|
+
# roomer :shared
|
28
|
+
# end
|
29
|
+
def inject_roomer_content
|
30
|
+
inject_into_class model_path, class_name do
|
31
|
+
<<-CONTENT
|
32
|
+
# tell roomer if this is a shared or tenanted model
|
33
|
+
roomer :#{shared? ? "shared" : "tenanted"}
|
34
|
+
CONTENT
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# Generates migration file of the model
|
39
|
+
def copy_roomer_migration
|
40
|
+
migration_template "migration.rb", "#{migration_dir}/roomer_create_#{table_name}"
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class RoomerCreate<%= table_name.camelize %> < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table(:<%= table_name %>) do |t|
|
4
|
+
<% for attribute in attributes -%>
|
5
|
+
t.<%= attribute.type %> :<%= attribute.name %>
|
6
|
+
<% end -%>
|
7
|
+
|
8
|
+
t.timestamps
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.down
|
13
|
+
drop_table :<%= table_name %>
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'rails/generators/active_record'
|
2
|
+
module Roomer
|
3
|
+
module Generators
|
4
|
+
class SetupGenerator < Rails::Generators::Base
|
5
|
+
include Rails::Generators::Migration
|
6
|
+
extend ActiveRecord::Generators::Migration
|
7
|
+
|
8
|
+
source_root File.expand_path("../templates", __FILE__)
|
9
|
+
desc "Generates the shared tables db migrations under #{Roomer.shared_migrations_directory} and generates the tenant model"
|
10
|
+
|
11
|
+
# Creates the Tenants model file under /app/models
|
12
|
+
def create_tenant_model_file
|
13
|
+
add_file File.join(Roomer.model_directory,"#{Roomer.tenants_table.to_s.singularize}.rb") do
|
14
|
+
<<-CONTENT
|
15
|
+
class #{Roomer.tenants_table.to_s.classify} < ActiveRecord::Base
|
16
|
+
# load tenanted schema.rb file to provision new tenant
|
17
|
+
after_create :load_schema
|
18
|
+
|
19
|
+
# tell roomer if this is a shared model
|
20
|
+
roomer :shared
|
21
|
+
|
22
|
+
protected
|
23
|
+
def load_schema
|
24
|
+
Roomer::Schema.load(schema_name)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
CONTENT
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# creates a migration file under /db/migrate/shared_schema_name
|
32
|
+
def create_migration_file
|
33
|
+
migration_template "global_migration.rb", "#{Roomer.shared_migrations_directory}/roomer_create_#{Roomer.tenants_table.to_s}"
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# Migration for the Roomer.tenants_table
|
2
|
+
class RoomerCreate<%= Roomer.tenants_table.to_s.camelize %> < ActiveRecord::Migration
|
3
|
+
def self.up
|
4
|
+
create_table(:<%= Roomer.tenants_table %>) do |t|
|
5
|
+
t.string :<%= Roomer.tenant_url_identifier_column %>
|
6
|
+
t.string :<%= Roomer.tenant_schema_name_column %>
|
7
|
+
|
8
|
+
# Add additional columns here
|
9
|
+
# t.string :name
|
10
|
+
t.timestamps
|
11
|
+
end
|
12
|
+
|
13
|
+
add_index :<%= Roomer.tenants_table %>, :<%= Roomer.tenant_url_identifier_column %>, :unique => true
|
14
|
+
add_index :<%= Roomer.tenants_table %>, :<%= Roomer.tenant_schema_name_column %>, :unique => true
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.down
|
18
|
+
drop_table :<%= Roomer.tenants_table %>
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Roomer
|
2
|
+
module Extensions
|
3
|
+
module Controller
|
4
|
+
def self.included(base)
|
5
|
+
base.before_filter :set_current_tenant!
|
6
|
+
end
|
7
|
+
|
8
|
+
protected
|
9
|
+
# Fetches the URL Identifier
|
10
|
+
# @return [True, False]
|
11
|
+
def url_identifier
|
12
|
+
case Roomer.url_routing_strategy
|
13
|
+
when :domain
|
14
|
+
return request.host
|
15
|
+
when :path
|
16
|
+
return params[:tenant_identifier]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
# Sets the current tenant, this method is set in the before_filter
|
21
|
+
# @throws if tenant is not found
|
22
|
+
def set_current_tenant!
|
23
|
+
# Raise an exception if the current tenant is blank
|
24
|
+
raise "No tenant found for '#{url_identifier}' url identifier" if current_tenant.blank?
|
25
|
+
Roomer.current_tenant = current_tenant
|
26
|
+
end
|
27
|
+
|
28
|
+
# Returns the current tenant
|
29
|
+
# @returns Roomer.tenant_model
|
30
|
+
# @see Roomer.model
|
31
|
+
def current_tenant
|
32
|
+
@current_tenant ||= Roomer.tenant_model.find_by_url_identifier(url_identifier)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|