Module: SimplyTheTenant
- Defined in:
- lib/simply_the_tenant.rb,
lib/simply_the_tenant/engine.rb,
lib/simply_the_tenant/version.rb,
lib/simply_the_tenant/model_ext.rb,
lib/simply_the_tenant/controller_ext.rb
Defined Under Namespace
Modules: ControllerExt, ModelExt
Classes: CurrentNeedsTenantError, Engine, MultipleTenantError, NilTenantError, NoSubdomainError, NoTenantSetError
Constant Summary
collapse
- VERSION =
"0.2.1"
- @@tenant_class =
nil
- @@global_access =
false
Class Method Summary
collapse
Class Method Details
.global_access? ⇒ Boolean
51
52
53
|
# File 'lib/simply_the_tenant.rb', line 51
def self.global_access?
@@global_access
end
|
.tenant ⇒ Object
31
32
33
34
35
|
# File 'lib/simply_the_tenant.rb', line 31
def self.tenant
raise CurrentNeedsTenantError unless Current.respond_to?(tenant_name)
Current.public_send(tenant_name)
end
|
.tenant=(tenant) ⇒ Object
37
38
39
40
41
|
# File 'lib/simply_the_tenant.rb', line 37
def self.tenant=(tenant)
raise CurrentNeedsTenantError unless Current.respond_to?("#{tenant_name}=")
Current.public_send("#{tenant_name}=", tenant)
end
|
.tenant_class ⇒ Object
15
16
17
|
# File 'lib/simply_the_tenant.rb', line 15
def self.tenant_class
@@tenant_class
end
|
.tenant_class=(klass) ⇒ Object
19
20
21
|
# File 'lib/simply_the_tenant.rb', line 19
def self.tenant_class=(klass)
@@tenant_class = klass
end
|
.tenant_id ⇒ Object
27
28
29
|
# File 'lib/simply_the_tenant.rb', line 27
def self.tenant_id
"#{tenant_name}_id"
end
|
.tenant_name ⇒ Object
23
24
25
|
# File 'lib/simply_the_tenant.rb', line 23
def self.tenant_name
@@tenant_class.name.underscore.to_sym
end
|
.with_global_access ⇒ Object
43
44
45
46
47
48
49
|
# File 'lib/simply_the_tenant.rb', line 43
def self.with_global_access
@@global_access = true
yield
ensure
@@global_access = false
end
|
.with_tenant(tenant) ⇒ Object
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/simply_the_tenant.rb', line 56
def self.with_tenant(tenant)
raise NilTenantError if tenant.nil?
previous_tenant = self.tenant
self.tenant = tenant
yield
ensure
self.tenant = previous_tenant
end
|