class Saasable::Middleware

Public Class Methods

new(app) click to toggle source
# File lib/saasable/middleware.rb, line 4
def initialize(app)
  @app = app
end

Public Instance Methods

call(env) click to toggle source
# File lib/saasable/middleware.rb, line 8
def call(env)
  return @app.call(env) if env['PATH_INFO'].start_with?('/assets')

  saas = saas_for_host(env['SERVER_NAME'])
  saas&.activate!

  @app.call(env).tap { saas&.deactivate! }
end

Private Instance Methods

saas_for_host(hostname) click to toggle source
# File lib/saasable/middleware.rb, line 19
def saas_for_host(hostname)
  Saasable::Mongoid::SaasDocument.saas_document.find_by_host!(hostname)
rescue Saasable::Errors::SaasNotFound
  nil # Saas not found is treated by the Rails Helper
end