class Tenantify::Middleware::Strategies::Default

Strategy to return always the same tenant.

@example Using Default strategy:

config   = {:tenant => :a_tenant}
strategy = Tenantify::Middleware::Strategies::Default.new(config)

env = {} # any environment
strategy.tenant_for(env) # => :a_tenant

Constants

NoTenantGivenError

No tenant given.

Attributes

config[R]

Public Class Methods

new(config) click to toggle source

Constructor.

@param [Hash] the strategy configuration. @option :tenant the tenant to return

# File lib/tenantify/middleware/strategies/default.rb, line 20
def initialize config
  @config = config
end

Public Instance Methods

tenant_for(_env) click to toggle source

Finds a tenant for the given env.

@param [rack_environment] the rack environment. @return [Symbol, nil] the found tenant of nil.

# File lib/tenantify/middleware/strategies/default.rb, line 28
def tenant_for _env
  tenant
end

Private Instance Methods

raise_error() click to toggle source
# File lib/tenantify/middleware/strategies/default.rb, line 40
def raise_error
  raise NoTenantGivenError
end
tenant() click to toggle source
# File lib/tenantify/middleware/strategies/default.rb, line 36
def tenant
  @tenant ||= config.fetch(:tenant) { raise_error }
end