Sha256: e1560972b72b3aa5d6becda02c3666ac379565ea5c422673908b36917d240903

Contents?: true

Size: 661 Bytes

Versions: 7

Compression:

Stored size: 661 Bytes

Contents

require 'rack/request'
require 'apartment/tenant'

module Apartment
  module Elevators
    #   Provides a rack based tenant switching solution based on request
    #
    class Generic

      def initialize(app, processor = nil)
        @app = app
        @processor = processor || method(:parse_tenant_name)
      end

      def call(env)
        request = Rack::Request.new(env)

        database = @processor.call(request)

        if database
          Apartment::Tenant.switch(database) { @app.call(env) }
        else
          @app.call(env)
        end
      end

      def parse_tenant_name(request)
        raise "Override"
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
ros-apartment-2.3.0 lib/apartment/elevators/generic.rb
ros-apartment-2.3.0.alpha2 lib/apartment/elevators/generic.rb
ros-apartment-2.3.0.alpha1 lib/apartment/elevators/generic.rb
apartment-2.2.1 lib/apartment/elevators/generic.rb
apartment-2.2.0 lib/apartment/elevators/generic.rb
apartment-2.1.0 lib/apartment/elevators/generic.rb
apartment-2.0.0 lib/apartment/elevators/generic.rb