class Tenantify::Middleware

Rack middleware responsible for setting the tenant during the http request.

This middleware builds a set of strategies from the given configuration, and sets the tenant returned from those strategies.

Attributes

app[R]
config[R]

Public Class Methods

new(app, config = Tenantify.configuration) click to toggle source

Constructor.

@param [#call] the Rack application @param [Tenantify::Configuration] the Rack application

# File lib/tenantify/middleware.rb, line 14
def initialize app, config = Tenantify.configuration
  @app    = app
  @config = config
end

Public Instance Methods

call(env) click to toggle source

Calls the rack middleware.

@param [rack_environment] the Rack environment @return [rack_response] the Rack response

# File lib/tenantify/middleware.rb, line 23
def call env
  tenant = strategies.tenant_for(env)

  Tenant.using(tenant) { app.call(env) }
end

Private Instance Methods

strategies() click to toggle source
# File lib/tenantify/middleware.rb, line 33
def strategies
  @strategies ||= begin
    builder = Builder.new(config)
    builder.call
  end
end