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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 85c62500154d550d5ff86498c72037952ee55c1b
4
- data.tar.gz: e9c3fdb92396c975c91619cf97862642c181b398
3
+ metadata.gz: 7a3eacc926211c4d312033d4ae884ffa6b96415f
4
+ data.tar.gz: dba26693200afd9ec2d8cb34e3ebdf5a448fc1c3
5
5
  SHA512:
6
- metadata.gz: 09005a519c83867edb1ee3671457d5fe8eb95424a505dedbfed2e84df0dc3d87a8deac4e0ae9885a8a97e26f3ab7b53161a64d716f3af3d2a699c0aa7da35fdf
7
- data.tar.gz: 88970e4a96def998b592181a27a2119fa69d1a08edd08dcb243934a3f76db208ff58acf45d17fbcc727edc891ee456f266fcc8415ee95245531376c392f6ea4b
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 :name, :theme, presence: true
4
- validates :theme, format: { with: /[a-z0-9_]+/ }
5
- serialize :configs, Hash
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_#{self.id}"
20
+ "tenant_#{id}"
20
21
  end
21
22
 
22
23
  def switch_to_tenant
23
- ::Apartment::Tenant.switch(self.schema_name)
24
+ ::Apartment::Tenant.switch(schema_name)
24
25
  end
25
26
 
26
- def theme_path
27
- "app/views/#{self.theme}"
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(self.schema_name)
44
+ ::Apartment::Tenant.create(schema_name)
34
45
  end
35
46
 
36
47
  def drop_schema
37
- ::Apartment::Tenant.drop(self.schema_name)
48
+ ::Apartment::Tenant.drop(schema_name)
38
49
  end
39
50
 
40
51
  end
@@ -2,7 +2,7 @@ class CreateTenanfyTenants < ActiveRecord::Migration
2
2
  def change
3
3
  create_table :tenanfy_tenants do |t|
4
4
  t.string :name , null: false
5
- t.string :theme , null: false
5
+ t.string :themes, null: false
6
6
  t.string :description
7
7
  t.string :keywords
8
8
  t.text :configs
@@ -4,7 +4,10 @@ module Tenanfy
4
4
 
5
5
  included do
6
6
  around_filter :setup_tenant_thread
7
- helper_method :current_tenant, :current_tenant_theme, :current_tenant_name
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
- prepend_tenant_theme
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 theme in the controller view path
30
- def prepend_tenant_theme
31
- prepend_view_path current_tenant.theme_path if current_tenant && current_tenant.theme_path
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
- current_tenant ? current_tenant.theme : ""
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
@@ -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 ? "#{current_tenant.theme}/#{asset}" : asset
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
@@ -1,3 +1,3 @@
1
1
  module Tenanfy
2
- VERSION = "0.0.7"
2
+ VERSION = "0.1.0"
3
3
  end
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.7
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-08-18 00:00:00.000000000 Z
11
+ date: 2014-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails