Module: MultiTenant::ActsAsTenant::TenantGetters

Defined in:
lib/multi_tenant/acts_as_tenant.rb

Instance Method Summary collapse

Instance Method Details

#current_tenantObject 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.

Returns:

  • the current tenant record



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_tenantsObject

Returns the array of current tenants. Thread-safe.

Returns:

  • the array of tenant records



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.

Returns:

  • (Boolean)


39
40
41
# File 'lib/multi_tenant/acts_as_tenant.rb', line 39

def current_tenants?
  current_tenants.any?
end