Module: MultiTenant::ActsAsTenant

Defined in:
lib/multi_tenant/acts_as_tenant.rb

Overview

Contains helpers to turn an ActiveRecord model into the tenant source.

Defined Under Namespace

Modules: TenantGetters, TenantHelpers, TenantSetters

Instance Method Summary collapse

Instance Method Details

#acts_as_tenant(using: :code) ⇒ Object

Use this ActiveRecord model as the tenant source.

Parameters:

  • using (String) (defaults to: :code)

    (optional) column that contains the unique lookup identifier. Defaults to :code.



14
15
16
17
18
19
20
21
22
# File 'lib/multi_tenant/acts_as_tenant.rb', line 14

def acts_as_tenant(using: :code)
  cattr_accessor :tenant_identifier, :tenant_thread_var, :raise_on_tenant_not_found
  self.tenant_identifier = using
  self.tenant_thread_var = "current_tenant_#{object_id}".freeze # allows there to be multiple tenant classes
  self.raise_on_tenant_not_found = true
  self.extend MultiTenant::ActsAsTenant::TenantGetters
  self.extend MultiTenant::ActsAsTenant::TenantSetters
  self.extend MultiTenant::ActsAsTenant::TenantHelpers
end

#acts_as_tenant?Boolean

Returns true if this model is being used as a tenant.

Returns:

  • (Boolean)


29
30
31
# File 'lib/multi_tenant/acts_as_tenant.rb', line 29

def acts_as_tenant?
  respond_to? :tenant_identifier
end