Module: Multitenant

Defined in:
lib/multitenant.rb,
lib/multitenant/version.rb,
lib/multitenant/schema_utils.rb

Overview

Multitenant: making cross tenant data leaks a thing of the past…since 2011

Defined Under Namespace

Modules: SchemaUtils

Constant Summary collapse

VERSION =
"0.1.0"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.current_tenantObject

Returns the value of attribute current_tenant.



6
7
8
# File 'lib/multitenant.rb', line 6

def current_tenant
  @current_tenant
end

Class Method Details

.with_tenant(tenant = nil, &block) ⇒ Object

execute a block scoped to the current tenant unsets the current tenant after execution



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/multitenant.rb', line 10

def with_tenant(tenant = nil, &block)
  previous_tenant = Multitenant.current_tenant
  Multitenant.current_tenant = tenant if tenant

  SchemaUtils.with_schema(Multitenant.current_tenant.schema_name) do
    yield
  end

ensure
  Multitenant.current_tenant = previous_tenant
end