Class: Tenantify::Middleware::Strategies
- Inherits:
-
Object
- Object
- Tenantify::Middleware::Strategies
- 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.
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
-
#initialize(strategies) ⇒ Strategies
constructor
Constructor.
-
#tenant_for(env) ⇒ Symbol
Find a tenant for the current env.
Constructor Details
#initialize(strategies) ⇒ Strategies
Constructor. It receives all strategies in order of precedence.
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.
34 35 36 |
# File 'lib/tenantify/middleware/strategies.rb', line 34 def tenant_for env find_tenant_for(env) or raise_error(env) end |