module Mongoid::Multitenancy
Constants
- VERSION
Version
Public Class Methods
current_tenant()
click to toggle source
Returns the current tenant
# File lib/mongoid/multitenancy.rb, line 16 def current_tenant Thread.current[:current_tenant] end
current_tenant=(tenant)
click to toggle source
Set the current tenant. Make it Thread aware
# File lib/mongoid/multitenancy.rb, line 11 def current_tenant=(tenant) Thread.current[:current_tenant] = tenant end
with_tenant(tenant) { || ... }
click to toggle source
Affects a tenant temporary for a block execution
# File lib/mongoid/multitenancy.rb, line 21 def with_tenant(tenant, &block) raise ArgumentError, 'block required' if block.nil? begin old_tenant = current_tenant self.current_tenant = tenant yield ensure self.current_tenant = old_tenant end end