Sha256: 10107ca8bbc5ca033f8127c7a4f8efa373c4cc40a54c6b66ed3723230d744557

Contents?: true

Size: 561 Bytes

Versions: 3

Compression:

Stored size: 561 Bytes

Contents

module Apartment
  module Elevators
    # Provides a rack based db switching solution based on subdomains
    # Assumes that database name should match subdomain
    class Subdomain

      def initialize(app)
        @app = app
      end

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

        database = subdomain(request)

        Apartment::Database.switch database if database

        @app.call(env)
      end

      def subdomain(request)
        request.subdomain.present? && request.subdomain || nil
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
apartment-0.15.0 lib/apartment/elevators/subdomain.rb
apartment-0.14.4 lib/apartment/elevators/subdomain.rb
apartment-0.14.3 lib/apartment/elevators/subdomain.rb