Sha256: 182ebf8bd485126bfd1ceffe74b7245108ab87f34cae6e6e83ed38e20fbd33be

Contents?: true

Size: 585 Bytes

Versions: 2

Compression:

Stored size: 585 Bytes

Contents

require 'apartment/elevators/generic'

module Apartment
  module Elevators
    #   Provides a rack based db switching solution based on hosts
    #   Uses a hash to find the corresponding database name for the host
    #
    class HostHash < Generic
      def initialize(app, hash = {}, processor = nil)
        super app, processor
        @hash = hash
      end

      def parse_tenant_name(request)
        raise DatabaseNotFound,
          "Cannot find database for host #{request.host}" unless @hash.has_key?(request.host)

        @hash[request.host]
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
apartment-0.23.2 lib/apartment/elevators/host_hash.rb
apartment-0.23.1 lib/apartment/elevators/host_hash.rb