Sha256: b2b6262c043341781bb67eaa23fab9f0ed20125c7118358181149f16e7bb81b1
Contents?: true
Size: 794 Bytes
Versions: 3
Compression:
Stored size: 794 Bytes
Contents
class Saasable::Middleware def initialize app @app = app # Loads all models so we know how to apply the scopes on Rails Rails::Mongoid.load_models(Rails.application) if defined?(Rails::Mongoid) end def call env return @app.call(env) if env['PATH_INFO'].start_with?('/assets') env[:saasable] = {:current_saas => saas_for_host(env['SERVER_NAME'])} env[:saasable][:current_saas].activate! if env[:saasable][:current_saas] @app.call(env).tap do env[:saasable][:current_saas].deactivate! if env[:saasable][:current_saas] end end private 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
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
saasable-4.0.2 | lib/saasable/middleware.rb |
saasable-4.0.1 | lib/saasable/middleware.rb |
saasable-4.0.0 | lib/saasable/middleware.rb |