Sha256: d9817c63ede6e80e9304548322c58feaeebf45a3a4695fc8f3408579292d2464

Contents?: true

Size: 1.16 KB

Versions: 16

Compression:

Stored size: 1.16 KB

Contents

#
# The Penthouse::App class defines a Rack middleware to be included into your
# stack before your main application is called.
#
# @example Typically in Rails you'd use:
#   Rails.application.config.middleware.use Penthouse::App, router: Penthouse::Routers::BaseRouter
#
# This app uses the router to determine the tenant instance, then calls the
# application within that tenant.
#

require 'rack/request'

module Penthouse
  class App
    attr_accessor :app, :router, :runner
    private :app=, :router=, :runner=

    # @param app the Rack application
    # @param router [#call] the class/proc to use as the router
    # @param runner [#call] the class/proc to use as the runner
    def initialize(app, router: Penthouse.configuration.router, runner: Penthouse.configuration.runner)
      self.app = app
      self.router = router
      self.runner = runner
    end

    # @param env [Hash] the environment passed from Rack
    # @raise [Penthouse::TenantNotFound] if the tenant cannot be found/switched to
    # @return [void]
    def call(env)
      request = Rack::Request.new(env)
      runner.call(router.call(request)) do
        app.call(env)
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
penthouse-0.11.0 lib/penthouse/app.rb
penthouse-0.10.1 lib/penthouse/app.rb
penthouse-0.10.0 lib/penthouse/app.rb
penthouse-0.9.0 lib/penthouse/app.rb
penthouse-0.8.0 lib/penthouse/app.rb
penthouse-0.7.5 lib/penthouse/app.rb
penthouse-0.7.4 lib/penthouse/app.rb
penthouse-0.7.3 lib/penthouse/app.rb
penthouse-0.7.2 lib/penthouse/app.rb
penthouse-0.7.1 lib/penthouse/app.rb
penthouse-0.7.0 lib/penthouse/app.rb
penthouse-0.6.0 lib/penthouse/app.rb
penthouse-0.5.0 lib/penthouse/app.rb
penthouse-0.4.2 lib/penthouse/app.rb
penthouse-0.4.1 lib/penthouse/app.rb
penthouse-0.4.0 lib/penthouse/app.rb