Class: TenantKit::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/tenant_kit/configuration.rb

Overview

Holds the gem's configuration. Access the singleton via config and set values in config/initializers/tenant_kit.rb through configure.

Examples:

TenantKit.configure do |config|
  config.tenant_class  = "Account"
  config.tenant_column = "account_id"
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



29
30
31
32
33
34
35
# File 'lib/tenant_kit/configuration.rb', line 29

def initialize
  @tenant_class                = "Account"
  @tenant_column               = "account_id"
  @require_tenant              = true
  @propagate_to_jobs           = true
  @raise_on_missing_job_tenant = false
end

Instance Attribute Details

#propagate_to_jobsBoolean

Returns carry the current tenant into ActiveJob background jobs.

Returns:

  • (Boolean)

    carry the current tenant into ActiveJob background jobs.



23
24
25
# File 'lib/tenant_kit/configuration.rb', line 23

def propagate_to_jobs
  @propagate_to_jobs
end

#raise_on_missing_job_tenantBoolean

Returns raise if a job is performed with no captured tenant (only consulted when #propagate_to_jobs is true).

Returns:

  • (Boolean)

    raise if a job is performed with no captured tenant (only consulted when #propagate_to_jobs is true).



27
28
29
# File 'lib/tenant_kit/configuration.rb', line 27

def raise_on_missing_job_tenant
  @raise_on_missing_job_tenant
end

#require_tenantBoolean

Returns strict mode: raise NoTenantSet when a tenant-scoped query runs with no current tenant (and not inside without_tenant).

Returns:

  • (Boolean)

    strict mode: raise NoTenantSet when a tenant-scoped query runs with no current tenant (and not inside without_tenant).



20
21
22
# File 'lib/tenant_kit/configuration.rb', line 20

def require_tenant
  @require_tenant
end

#tenant_classString

Returns name of the model that represents a tenant (e.g. "Account").

Returns:

  • (String)

    name of the model that represents a tenant (e.g. "Account").



13
14
15
# File 'lib/tenant_kit/configuration.rb', line 13

def tenant_class
  @tenant_class
end

#tenant_columnString

Returns foreign-key column on tenant-owned tables (e.g. "account_id").

Returns:

  • (String)

    foreign-key column on tenant-owned tables (e.g. "account_id").



16
17
18
# File 'lib/tenant_kit/configuration.rb', line 16

def tenant_column
  @tenant_column
end

Instance Method Details

#tenant_modelClass

Resolves #tenant_class to the actual constant, lazily so it works with Rails autoloading / reloading.

Returns:

  • (Class)

    the tenant model class.



41
42
43
# File 'lib/tenant_kit/configuration.rb', line 41

def tenant_model
  tenant_class.to_s.constantize
end