Sha256: 69deace1f84ef130890811d627d0ead926c32624691df3042813d235589badf9

Contents?: true

Size: 556 Bytes

Versions: 6

Compression:

Stored size: 556 Bytes

Contents

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

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

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

        database = @processor.call(request)

        Apartment::Database.switch database if database

        @app.call(env)
      end

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
apartment-0.22.1 lib/apartment/elevators/generic.rb
apartment-0.22.0 lib/apartment/elevators/generic.rb
apartment-0.21.1 lib/apartment/elevators/generic.rb
apartment-0.21.0 lib/apartment/elevators/generic.rb
apartment-0.20.0 lib/apartment/elevators/generic.rb
apartment-0.19.0 lib/apartment/elevators/generic.rb