Module: Mongoid::Multitenancy
- Defined in:
- lib/mongoid/multitenancy.rb,
lib/mongoid/multitenancy/version.rb,
lib/mongoid/multitenancy/document.rb
Defined Under Namespace
Modules: Document
Constant Summary collapse
- VERSION =
"0.4.2"
Class Method Summary collapse
-
.current_tenant ⇒ Object
Returns the current tenant.
-
.current_tenant=(tenant) ⇒ Object
Set the current tenant.
-
.mongoid4? ⇒ Boolean
Returns true if using Mongoid 4.
-
.with_tenant(tenant, &block) ⇒ Object
Affects a tenant temporary for a block execution.
Class Method Details
.current_tenant ⇒ Object
Returns the current tenant
21 22 23 |
# File 'lib/mongoid/multitenancy.rb', line 21 def current_tenant Thread.current[:current_tenant] end |
.current_tenant=(tenant) ⇒ Object
Set the current tenant. Make it Thread aware
16 17 18 |
# File 'lib/mongoid/multitenancy.rb', line 16 def current_tenant=(tenant) Thread.current[:current_tenant] = tenant end |
.mongoid4? ⇒ Boolean
Returns true if using Mongoid 4
11 12 13 |
# File 'lib/mongoid/multitenancy.rb', line 11 def mongoid4? Mongoid::VERSION.start_with? '4' end |
.with_tenant(tenant, &block) ⇒ Object
Affects a tenant temporary for a block execution
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/mongoid/multitenancy.rb', line 26 def with_tenant(tenant, &block) if block.nil? raise ArgumentError, "block required" end old_tenant = self.current_tenant self.current_tenant = tenant block.call self.current_tenant = old_tenant end |