Module: Penthouse
- Defined in:
- lib/penthouse/configuration.rb,
lib/penthouse.rb,
lib/penthouse/app.rb,
lib/penthouse/sidekiq.rb,
lib/penthouse/version.rb,
lib/penthouse/migrator.rb,
lib/penthouse/migrator.rb,
lib/penthouse/tasks/enhancements.rb,
lib/penthouse/tenants/migratable.rb,
lib/penthouse/routers/base_router.rb,
lib/penthouse/runners/base_runner.rb,
lib/penthouse/tenants/base_tenant.rb,
lib/penthouse/runners/schema_runner.rb,
lib/penthouse/tenants/schema_tenant.rb,
lib/penthouse/routers/subdomain_router.rb,
lib/penthouse/tenants/octopus_shard_tenant.rb,
lib/penthouse/tenants/octopus_schema_tenant.rb
Overview
This router will load the tenant name based on a request’s sub-domain
Defined Under Namespace
Modules: Migration, Migrator, Routers, Runners, Sidekiq, Tenants Classes: App, Configuration, RakeTaskEnhancer, TenantNotFound
Constant Summary collapse
- VERSION =
"0.7.0"
Class Method Summary collapse
-
.configuration ⇒ Penthouse::Configuration
Returns the current configuration of Penthouse.
-
.configure {|Penthouse::Configuration| ... } ⇒ void
Allows you to configure the router of Penthouse.
-
.create(tenant_identifier, runner: configuration.runner, **options) ⇒ void
Loads the tenant and creates their data store.
-
.delete(tenant_identifier, runner: configuration.runner, **options) ⇒ void
Loads the tenant and deletes their data store.
-
.each_tenant(tenant_identifiers: nil, default_tenant: tenant, runner: configuration.runner, &block) {|String, Symbol| ... } ⇒ void
Wraps Penthouse.switch and simply executes the block of code for each tenant within Penthouse.tenant_identifiers.
-
.switch(tenant_identifier, runner: configuration.runner, &block) {|Penthouse::Tenants::BaseTenant| ... } ⇒ void
Executes the given block of code within a given tenant.
-
.tenant ⇒ String, Symbol
Retrieves the currently active tenant identifier.
-
.tenant=(tenant_identifier) ⇒ void
Sets the currently active tenant identifier.
-
.tenant_identifiers ⇒ Array<String, Symbol>
Returns a array of tenant identifiers based on the configured setting.
-
.with_tenant(tenant_identifier, default_tenant: tenant, &block) {|String, Symbol| ... } ⇒ void
Similar to Penthouse.tenant=, except this will switch back after the given block has finished executing.
Class Method Details
.configuration ⇒ Penthouse::Configuration
Returns the current configuration of Penthouse
93 94 95 96 97 98 |
# File 'lib/penthouse.rb', line 93 def configuration @configuration ||= Configuration.new( router: Routers::BaseRouter, runner: Runners::BaseRunner ) end |
.configure {|Penthouse::Configuration| ... } ⇒ void
This method returns an undefined value.
Allows you to configure the router of Penthouse
84 85 86 87 88 89 |
# File 'lib/penthouse.rb', line 84 def configure(&block) # allow the configuration by the block block.yield(self.configuration) # prevent modification of configuration once set self.configuration.freeze end |
.create(tenant_identifier, runner: configuration.runner, **options) ⇒ void
This method returns an undefined value.
Loads the tenant and creates their data store
65 66 67 68 69 |
# File 'lib/penthouse.rb', line 65 def create(tenant_identifier, runner: configuration.runner, **) switch(tenant_identifier, runner: runner) do |tenant| tenant.create(**) end end |
.delete(tenant_identifier, runner: configuration.runner, **options) ⇒ void
This method returns an undefined value.
Loads the tenant and deletes their data store
75 76 77 78 79 |
# File 'lib/penthouse.rb', line 75 def delete(tenant_identifier, runner: configuration.runner, **) switch(tenant_identifier, runner: runner) do |tenant| tenant.delete(**) end end |
.each_tenant(tenant_identifiers: nil, default_tenant: tenant, runner: configuration.runner, &block) {|String, Symbol| ... } ⇒ void
This method returns an undefined value.
Wraps Penthouse.switch and simply executes the block of code for each tenant within Penthouse.tenant_identifiers
45 46 47 48 49 |
# File 'lib/penthouse.rb', line 45 def each_tenant(tenant_identifiers: nil, default_tenant: tenant, runner: configuration.runner, &block) (tenant_identifiers || self.tenant_identifiers).each do |tenant_identifier| switch(tenant_identifier, runner: runner, &block) end end |
.switch(tenant_identifier, runner: configuration.runner, &block) {|Penthouse::Tenants::BaseTenant| ... } ⇒ void
This method returns an undefined value.
Executes the given block of code within a given tenant
57 58 59 |
# File 'lib/penthouse.rb', line 57 def switch(tenant_identifier, runner: configuration.runner, &block) runner.call(tenant_identifier, &block) end |
.tenant ⇒ String, Symbol
Retrieves the currently active tenant identifier
13 14 15 |
# File 'lib/penthouse.rb', line 13 def tenant Thread.current[:tenant] end |
.tenant=(tenant_identifier) ⇒ void
This method returns an undefined value.
Sets the currently active tenant identifier
20 21 22 |
# File 'lib/penthouse.rb', line 20 def tenant=(tenant_identifier) Thread.current[:tenant] = tenant_identifier end |
.tenant_identifiers ⇒ Array<String, Symbol>
Returns a array of tenant identifiers based on the configured setting
102 103 104 |
# File 'lib/penthouse.rb', line 102 def tenant_identifiers configuration.tenant_identifiers.call end |
.with_tenant(tenant_identifier, default_tenant: tenant, &block) {|String, Symbol| ... } ⇒ void
This method returns an undefined value.
Similar to Penthouse.tenant=, except this will switch back after the given block has finished executing
31 32 33 34 35 36 |
# File 'lib/penthouse.rb', line 31 def with_tenant(tenant_identifier, default_tenant: tenant, &block) self.tenant = tenant_identifier block.yield(tenant_identifier) ensure self.tenant = default_tenant end |