lib/saasable/middleware.rb in saasable-5.0.5 vs lib/saasable/middleware.rb in saasable-5.1.0

- old
+ new

@@ -1,20 +1,23 @@ +# frozen_string_literal: true + class Saasable::Middleware - def initialize app + def initialize(app) @app = app end - def call env + def call(env) return @app.call(env) if env['PATH_INFO'].start_with?('/assets') saas = saas_for_host(env['SERVER_NAME']) - saas.activate! if saas + saas&.activate! - @app.call(env).tap { saas.deactivate! if saas } + @app.call(env).tap { saas&.deactivate! } end private - def saas_for_host hostname + + 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 end