Class: Apartment::Elevators::HostHash

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

Overview

Tenant from hostname -> tenant hash mapping. Raises TenantNotFound when host is not in the hash (explicit mapping; missing = config error).

Instance Method Summary collapse

Methods inherited from Generic

#call

Constructor Details

#initialize(app, hash: {}, **_options) ⇒ HostHash

Returns a new instance of HostHash.



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

def initialize(app, hash: {}, **_options)
  super(app)
  @hash = hash.freeze
end

Instance Method Details

#parse_tenant_name(request) ⇒ Object

Raises:



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

def parse_tenant_name(request)
  raise(TenantNotFound, request.host) unless @hash.key?(request.host)

  @hash[request.host]
end