lib/penthouse.rb in penthouse-0.3.0 vs lib/penthouse.rb in penthouse-0.4.0
- old
+ new
@@ -1,5 +1,6 @@
+require "penthouse/railtie" if defined?(Rails)
require "penthouse/version"
require "penthouse/configuration"
require "penthouse/routers/base_router"
require "penthouse/runners/base_runner"
@@ -13,20 +14,22 @@
Thread.current[:tenant]
end
# Sets the currently active tenant identifier
# @param tenant_identifier [String, Symbol] the identifier for the tenant
+ # @return [void]
def tenant=(tenant_identifier)
Thread.current[:tenant] = tenant_identifier
end
# Similar to Penthouse.tenant=, except this will switch back after the given
# block has finished executing
# @param tenant_identifier [String, Symbol] the identifier for the tenant
# @param default_tenant [String, Symbol] the identifier for the tenant to return to
# @param block [Block] the code to execute
# @yield [String, Symbol] the identifier for the tenant
+ # @return [void]
def with_tenant(tenant_identifier, default_tenant: tenant, &block)
self.tenant = tenant_identifier
block.yield(tenant_identifier)
ensure
self.tenant = default_tenant
@@ -35,10 +38,11 @@
# Wraps Penthouse.switch and simply executes the block of code for each
# tenant within Penthouse.tenant_identifiers
# @param default_tenant [String, Symbol] the identifier for the tenant to return to
# @param block [Block] the code to execute
# @yield [String, Symbol] the identifier for the tenant
+ # @return [void]
def each_tenant(default_tenant: tenant, runner: configuration.runner, &block)
tenant_identifiers.each do |tenant_identifier|
switch(tenant_identifier, runner: runner, &block)
end
end
@@ -46,33 +50,37 @@
# Executes the given block of code within a given tenant
# @param tenant_identifier [String, Symbol] the identifier for the tenant
# @param runner [Penthouse::Runners::BaseRunner] an optional runner to use, defaults to the one configured
# @param block [Block] the code to execute
# @yield [Penthouse::Tenants::BaseTenant] the tenant instance
+ # @return [void]
def switch(tenant_identifier, runner: configuration.runner, &block)
runner.call(tenant_identifier, &block)
end
# Loads the tenant and creates their data store
# @param tenant_identifier [String, Symbol] the identifier for the tenant
# @see Penthouse::Tenants::BaseTenant#delete
+ # @return [void]
def create(tenant_identifier, runner: configuration.runner, **options)
switch(tenant_identifier, runner: runner) do |tenant|
tenant.create(**options)
end
end
# Loads the tenant and deletes their data store
# @param tenant_identifier [String, Symbol] the identifier for the tenant
# @see Penthouse::Tenants::BaseTenant#delete
+ # @return [void]
def delete(tenant_identifier, runner: configuration.runner, **options)
switch(tenant_identifier, runner: runner) do |tenant|
tenant.delete(**options)
end
end
# Allows you to configure the router of Penthouse
# @yield [Penthouse::Configuration]
+ # @return [void]
def configure(&block)
# allow the configuration by the block
block.yield(self.configuration)
# prevent modification of configuration once set
self.configuration.freeze