Class: Tenantify::Middleware::Strategies

Inherits:
Object
  • Object
show all
Defined in:
lib/tenantify/middleware/strategies.rb,
lib/tenantify/middleware/strategies/host.rb,
lib/tenantify/middleware/strategies/header.rb,
lib/tenantify/middleware/strategies/default.rb

Overview

Responsible for finding the tenant for the given env.

It iterates the strategies given to the constructor until it finds one that returns a tenant.

Default strategy

When there is no matching strategy for the current environment a NotMatchingStrategyError is raised. To avoid this behaviour and use a particular tenant by default a Default strategy is provided.

Examples:

Configuring a tenant by default:

Tenantify.configure do |config|
  # your strategies

  config.strategy :default, :tenant => :my_default_tenant
end

Defined Under Namespace

Classes: Default, Header, Host

Constant Summary collapse

NotMatchingStrategyError =

None strategy found a valid tenant for the given environment

Class.new(StandardError)

Instance Method Summary collapse

Constructor Details

#initialize(strategies) ⇒ Strategies

Constructor. It receives all strategies in order of precedence.

Parameters:



26
27
28
# File 'lib/tenantify/middleware/strategies.rb', line 26

def initialize strategies
  @strategies = strategies
end

Instance Method Details

#tenant_for(env) ⇒ Symbol

Find a tenant for the current env.

Parameters:

  • current (rack_environment)

    env.

Returns:

  • (Symbol)

    returns the matching tenant.



34
35
36
# File 'lib/tenantify/middleware/strategies.rb', line 34

def tenant_for env
  find_tenant_for(env) or raise_error(env)
end