Module: MultiTenant
- Defined in:
- lib/activerecord-multi-tenant/version.rb,
lib/activerecord-multi-tenant/migrations.rb,
lib/activerecord-multi-tenant/multi_tenant.rb,
lib/activerecord-multi-tenant/copy_from_client.rb,
lib/activerecord-multi-tenant/model_extensions.rb,
lib/activerecord-multi-tenant/controller_extensions.rb
Defined Under Namespace
Modules: ControllerExtensions, CopyFromClient, MigrationExtensions, ModelExtensionsClassMethods
Classes: CopyFromClientHelper, TenantIdWrapper, TenantIsImmutable
Constant Summary
collapse
- VERSION =
'0.3.4'
- @@tenant_klass =
nil
- @@enable_with_lock_workaround =
false
Class Method Summary
collapse
Class Method Details
.current_tenant ⇒ Object
27
28
29
|
# File 'lib/activerecord-multi-tenant/multi_tenant.rb', line 27
def self.current_tenant
RequestStore.store[:current_tenant]
end
|
.current_tenant=(tenant) ⇒ Object
23
24
25
|
# File 'lib/activerecord-multi-tenant/multi_tenant.rb', line 23
def self.current_tenant=(tenant)
RequestStore.store[:current_tenant] = tenant
end
|
.current_tenant_id ⇒ Object
35
36
37
|
# File 'lib/activerecord-multi-tenant/multi_tenant.rb', line 35
def self.current_tenant_id
current_tenant.try(:id)
end
|
.current_tenant_id=(tenant_id) ⇒ Object
31
32
33
|
# File 'lib/activerecord-multi-tenant/multi_tenant.rb', line 31
def self.current_tenant_id=(tenant_id)
self.current_tenant = TenantIdWrapper.new(id: tenant_id)
end
|
.enable_with_lock_workaround ⇒ Object
20
|
# File 'lib/activerecord-multi-tenant/multi_tenant.rb', line 20
def self.enable_with_lock_workaround; @@enable_with_lock_workaround = true; end
|
.partition_key ⇒ Object
14
15
16
|
# File 'lib/activerecord-multi-tenant/multi_tenant.rb', line 14
def self.partition_key
"#{@@tenant_klass.to_s}_id"
end
|
.set_tenant_klass(klass) ⇒ Object
6
7
8
|
# File 'lib/activerecord-multi-tenant/multi_tenant.rb', line 6
def self.set_tenant_klass(klass)
@@tenant_klass = klass
end
|
.tenant_klass ⇒ Object
10
11
12
|
# File 'lib/activerecord-multi-tenant/multi_tenant.rb', line 10
def self.tenant_klass
@@tenant_klass
end
|
.with(tenant, &block) ⇒ Object
39
40
41
42
43
44
45
46
47
|
# File 'lib/activerecord-multi-tenant/multi_tenant.rb', line 39
def self.with(tenant, &block)
old_tenant = self.current_tenant
self.current_tenant = tenant
value = block.call
return value
ensure
self.current_tenant = old_tenant
end
|
.with_id(tenant_id, &block) ⇒ Object
.with_lock_workaround_enabled? ⇒ Boolean
21
|
# File 'lib/activerecord-multi-tenant/multi_tenant.rb', line 21
def self.with_lock_workaround_enabled?; @@enable_with_lock_workaround; end
|