Module: TenantKit::ControllerConcern

Extended by:
ActiveSupport::Concern
Defined in:
lib/tenant_kit/controller_concern.rb

Overview

Mixed into ActionController::Base and ActionController::API (via the railtie). Provides class-level helpers that install a before_action to resolve and set the current tenant for each request. CurrentAttributes resets the tenant automatically between requests.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.tenant_model_for(tenant_name) ⇒ Class

Resolves the tenant model class for the given (optional) name.

Parameters:

  • tenant_name (Symbol, String, nil)

Returns:

  • (Class)


63
64
65
66
67
# File 'lib/tenant_kit/controller_concern.rb', line 63

def self.tenant_model_for(tenant_name)
  return TenantKit.config.tenant_model if tenant_name.nil?

  tenant_name.to_s.camelize.constantize
end

Instance Method Details

#current_tenantObject?

Returns the current tenant for this request.

Returns:

  • (Object, nil)

    the current tenant for this request.



74
75
76
# File 'lib/tenant_kit/controller_concern.rb', line 74

def current_tenant
  TenantKit::Current.tenant
end

#current_tenant=(tenant) ⇒ Object?

Sets the current tenant for this request.

Parameters:

  • tenant (Object, nil)

Returns:

  • (Object, nil)


82
83
84
# File 'lib/tenant_kit/controller_concern.rb', line 82

def current_tenant=(tenant)
  TenantKit::Current.tenant = tenant
end