tenanfy 0.0.7 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/tenanfy/tenant.rb +20 -9
- data/db/migrate/20130128025640_create_tenanfy_tenants.rb +1 -1
- data/lib/tenanfy/controller.rb +15 -8
- data/lib/tenanfy/helpers.rb +5 -1
- data/lib/tenanfy/version.rb +1 -1
- 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: 7a3eacc926211c4d312033d4ae884ffa6b96415f
|
4
|
+
data.tar.gz: dba26693200afd9ec2d8cb34e3ebdf5a448fc1c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b418e038172548bccd95bd59545521e6d9cc421f06525667d7f9753552719edc93aebd05aa4968d37fca92c77b68270922726c2d0e08c9b1ea93274f9ee63863
|
7
|
+
data.tar.gz: 525ffcc1d9d67cfb2db83848d689144a0d75883ac400dd8a726e45eebcada42d1ca07be88af6f7b46977317e4c3b6ee6ab15e0a85667831b297da2b7dd9e0068
|
@@ -1,8 +1,9 @@
|
|
1
1
|
module Tenanfy
|
2
2
|
class Tenant < ActiveRecord::Base
|
3
|
-
validates
|
4
|
-
|
5
|
-
serialize
|
3
|
+
validates :name, :themes, presence: true
|
4
|
+
validate :validate_themes
|
5
|
+
serialize :configs, Hash
|
6
|
+
serialize :themes, Array
|
6
7
|
|
7
8
|
has_many :urls, inverse_of: :tenant
|
8
9
|
|
@@ -16,25 +17,35 @@ module Tenanfy
|
|
16
17
|
end
|
17
18
|
|
18
19
|
def schema_name
|
19
|
-
"tenant_#{
|
20
|
+
"tenant_#{id}"
|
20
21
|
end
|
21
22
|
|
22
23
|
def switch_to_tenant
|
23
|
-
::Apartment::Tenant.switch(
|
24
|
+
::Apartment::Tenant.switch(schema_name)
|
24
25
|
end
|
25
26
|
|
26
|
-
def
|
27
|
-
|
27
|
+
def theme_paths
|
28
|
+
themes.map do |theme|
|
29
|
+
"app/views/#{theme}"
|
30
|
+
end
|
28
31
|
end
|
29
32
|
|
30
33
|
private
|
31
34
|
|
35
|
+
def validate_themes
|
36
|
+
themes.each do |theme|
|
37
|
+
if theme !~ /[a-z0-9_]+/
|
38
|
+
errors.add(:themes, "#{theme} is not in the correct format.")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
32
43
|
def build_schema
|
33
|
-
::Apartment::Tenant.create(
|
44
|
+
::Apartment::Tenant.create(schema_name)
|
34
45
|
end
|
35
46
|
|
36
47
|
def drop_schema
|
37
|
-
::Apartment::Tenant.drop(
|
48
|
+
::Apartment::Tenant.drop(schema_name)
|
38
49
|
end
|
39
50
|
|
40
51
|
end
|
data/lib/tenanfy/controller.rb
CHANGED
@@ -4,7 +4,10 @@ module Tenanfy
|
|
4
4
|
|
5
5
|
included do
|
6
6
|
around_filter :setup_tenant_thread
|
7
|
-
helper_method :current_tenant, :
|
7
|
+
helper_method :current_tenant, :current_tenant_themes, :current_tenant_name
|
8
|
+
helper_method :current_tenant_themes
|
9
|
+
helper_method :current_tenant_theme
|
10
|
+
helper_method :current_tenant_name
|
8
11
|
end
|
9
12
|
|
10
13
|
private
|
@@ -19,16 +22,17 @@ module Tenanfy
|
|
19
22
|
def setup_tenant_thread
|
20
23
|
RequestStore.store[:tenant] = current_tenant
|
21
24
|
on_tenant_change
|
22
|
-
|
25
|
+
prepend_tenant_themes
|
23
26
|
yield
|
24
27
|
ensure
|
25
28
|
after_tenant_change
|
26
29
|
RequestStore.store[:tenant] = nil
|
27
30
|
end
|
28
31
|
|
29
|
-
# Adds the tenant
|
30
|
-
def
|
31
|
-
|
32
|
+
# Adds the tenant themes in the controller view path
|
33
|
+
def prepend_tenant_themes
|
34
|
+
return unless current_tenant && current_tenant.theme_paths
|
35
|
+
prepend_view_path current_tenant.theme_paths
|
32
36
|
end
|
33
37
|
|
34
38
|
# Returns the current tenant for this request
|
@@ -36,9 +40,13 @@ module Tenanfy
|
|
36
40
|
@current_tenant ||= Tenant.find_by_domain(request.host)
|
37
41
|
end
|
38
42
|
|
39
|
-
# Returns the current tenant theme
|
40
43
|
def current_tenant_theme
|
41
|
-
|
44
|
+
current_tenant_themes.first.to_s
|
45
|
+
end
|
46
|
+
|
47
|
+
# Returns the current tenant themes
|
48
|
+
def current_tenant_themes
|
49
|
+
current_tenant ? current_tenant.themes : []
|
42
50
|
end
|
43
51
|
|
44
52
|
# Returns the current tenant name
|
@@ -48,6 +56,5 @@ module Tenanfy
|
|
48
56
|
|
49
57
|
def on_tenant_change; end
|
50
58
|
def after_tenant_change; end
|
51
|
-
|
52
59
|
end
|
53
60
|
end
|
data/lib/tenanfy/helpers.rb
CHANGED
@@ -23,7 +23,11 @@ module Tenanfy
|
|
23
23
|
#
|
24
24
|
def append_tenant_theme_to_assets(*assets)
|
25
25
|
assets.map! do |asset|
|
26
|
-
should_add_tenant_theme_to_asset?(asset) && current_tenant
|
26
|
+
if should_add_tenant_theme_to_asset?(asset) && current_tenant
|
27
|
+
"#{current_tenant.themes.first}/#{asset}"
|
28
|
+
else
|
29
|
+
asset
|
30
|
+
end
|
27
31
|
end
|
28
32
|
assets
|
29
33
|
end
|
data/lib/tenanfy/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tenanfy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tiago Scolari
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-09-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|