Module: MultiTenant::ActsAsTenant::TenantGetters
- Defined in:
- lib/multi_tenant/acts_as_tenant.rb
Instance Method Summary collapse
-
#current_tenant ⇒ Object
(also: #current)
Return the current tenant record, if any.
-
#current_tenants ⇒ Object
Returns the array of current tenants.
-
#current_tenants? ⇒ Boolean
(also: #current?, #current_tenant?)
Returns true if there are any current tenants set, false if not.
Instance Method Details
#current_tenant ⇒ Object Also known as: current
Return the current tenant record, if any. Thread-safe. If there are MULTIPLE current tenants set this will raise a RuntimeError.
60 61 62 63 64 65 66 67 |
# File 'lib/multi_tenant/acts_as_tenant.rb', line 60 def current_tenant tenants = current_tenants if tenants.size > 1 raise "#{self.name}.current/current_tenant was called when multiple current tenants were present?. Did you mean to call #{self.name}.current_tenants?" else tenants[0] end end |
#current_tenants ⇒ Object
Returns the array of current tenants. Thread-safe.
50 51 52 |
# File 'lib/multi_tenant/acts_as_tenant.rb', line 50 def current_tenants Thread.current.thread_variable_get(tenant_thread_var) || [] end |
#current_tenants? ⇒ Boolean Also known as: current?, current_tenant?
Returns true if there are any current tenants set, false if not.
39 40 41 |
# File 'lib/multi_tenant/acts_as_tenant.rb', line 39 def current_tenants? current_tenants.any? end |