Module: MultiTenantSupport
- Defined in:
- lib/multi-tenant-support.rb,
lib/multi_tenant_support/errors.rb,
lib/multi_tenant_support/current.rb,
lib/multi_tenant_support/railtie.rb,
lib/multi_tenant_support/sidekiq.rb,
lib/multi_tenant_support/version.rb,
lib/multi_tenant_support/active_job.rb,
lib/multi_tenant_support/config/app.rb,
lib/multi_tenant_support/test/system.rb,
lib/multi_tenant_support/config/model.rb,
lib/multi_tenant_support/test/capybara.rb,
lib/multi_tenant_support/config/console.rb,
lib/multi_tenant_support/test/integration.rb,
lib/multi_tenant_support/config/controller.rb,
lib/multi_tenant_support/find_tenant_account.rb,
lib/multi_tenant_support/concern/model_concern.rb,
lib/multi_tenant_support/concern/controller_concern.rb,
lib/generators/multi_tenant_support/migration_generator.rb,
lib/generators/multi_tenant_support/initializer_generator.rb
Defined Under Namespace
Modules: ActiveJob, Config, ConfiguredJob, ControllerConcern, Generators, ModelConcern, Sidekiq, Test, ViewHelper
Classes: Current, Error, FindTenantAccount, ImmutableTenantError, InvalidTenantAccess, MissingTenantError, NilTenantError, Railtie
Constant Summary
collapse
- PROTECTED =
1
- PROTECTED_EXCEPT_READ =
Scoped and protected except read across tenant
2
- UNPROTECTED =
3
- VERSION =
'1.5.0'
Class Method Summary
collapse
Class Method Details
.allow_read_across_tenant ⇒ Object
.allow_read_across_tenant? ⇒ Boolean
.app {|@app| ... } ⇒ Object
19
20
21
22
23
24
|
# File 'lib/multi_tenant_support/config/app.rb', line 19
def app
@app ||= Config::App.new
return @app unless block_given?
yield @app
end
|
17
18
19
|
# File 'lib/multi-tenant-support.rb', line 17
def configure(&block)
instance_eval(&block)
end
|
.console {|@console| ... } ⇒ Object
14
15
16
17
18
19
|
# File 'lib/multi_tenant_support/config/console.rb', line 14
def console
@console ||= Config::Console.new
return @console unless block_given?
yield @console
end
|
.controller {|@controller| ... } ⇒ Object
15
16
17
18
19
20
|
# File 'lib/multi_tenant_support/config/controller.rb', line 15
def controller
@controller ||= Config::Controller.new
return @controller unless block_given?
yield @controller
end
|
.current_tenant ⇒ Object
21
22
23
|
# File 'lib/multi-tenant-support.rb', line 21
def current_tenant
Current.tenant_account
end
|
.current_tenant_account_method ⇒ Object
22
23
24
|
# File 'lib/multi_tenant_support/config/controller.rb', line 22
def current_tenant_account_method
controller.current_tenant_account_method
end
|
.current_tenant_id ⇒ Object
25
26
27
|
# File 'lib/multi-tenant-support.rb', line 25
def current_tenant_id
Current.tenant_account&.send(model.tenant_account_primary_key)
end
|
.full_protected? ⇒ Boolean
.model {|@model| ... } ⇒ Object
30
31
32
33
34
35
|
# File 'lib/multi_tenant_support/config/model.rb', line 30
def model
@model ||= Config::Model.new
return @model unless block_given?
yield @model
end
|
.set_current_tenant(tenant) ⇒ Object
.turn_off_protection ⇒ Object
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/multi-tenant-support.rb', line 62
def turn_off_protection
raise 'Cannot turn off protection, try wrap in without_current_tenant' if current_tenant
if block_given?
Current.set(protection_state: UNPROTECTED) do
yield
end
else
Current.protection_state = UNPROTECTED
end
end
|
.turn_on_full_protection ⇒ Object
.under_tenant(tenant_account, &block) ⇒ Object
34
35
36
37
38
39
40
|
# File 'lib/multi-tenant-support.rb', line 34
def under_tenant(tenant_account, &block)
raise ArgumentError, "block is missing" if block.nil?
Current.set(tenant_account: tenant_account, protection_state: PROTECTED) do
yield
end
end
|
.without_current_tenant(&block) ⇒ Object
42
43
44
45
46
47
48
|
# File 'lib/multi-tenant-support.rb', line 42
def without_current_tenant(&block)
raise ArgumentError, "block is missing" if block.nil?
Current.set(tenant_account: nil) do
yield
end
end
|