Class: Apartment::Elevators::HostHash

Inherits:
Generic
  • Object
show all
Defined in:
lib/apartment/elevators/host_hash.rb

Overview

Provides a rack based tenant switching solution based on hosts

Uses a hash to find the corresponding tenant name for the host

Instance Method Summary collapse

Methods inherited from Generic

#call, #deprecation_warning, #parse_database_name, #parse_method

Constructor Details

#initialize(app, hash = {}, processor = nil) ⇒ HostHash


9
10
11
12
# File 'lib/apartment/elevators/host_hash.rb', line 9

def initialize(app, hash = {}, processor = nil)
  super app, processor
  @hash = hash
end

Instance Method Details

#parse_tenant_name(request) ⇒ Object

Raises:


14
15
16
17
18
19
# File 'lib/apartment/elevators/host_hash.rb', line 14

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

  @hash[request.host]
end