Class: Apartment::Elevators::Subdomain

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

Overview

Provides a rack based tenant switching solution based on subdomains

Assumes that tenant name should match subdomain

Direct Known Subclasses

FirstSubdomain

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Generic

#call, #initialize

Constructor Details

This class inherits a constructor from Apartment::Elevators::Generic

Class Method Details

.excluded_subdomainsObject



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

def self.excluded_subdomains
  @excluded_subdomains ||= []
end

.excluded_subdomains=(arg) ⇒ Object



14
15
16
# File 'lib/apartment/elevators/subdomain.rb', line 14

def self.excluded_subdomains=(arg)
  @excluded_subdomains = arg
end

Instance Method Details

#parse_tenant_name(request) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/apartment/elevators/subdomain.rb', line 18

def parse_tenant_name(request)
  request_subdomain = subdomain(request.host)

  # If the domain acquired is set to be excluded, set the tenant to whatever is currently
  # next in line in the schema search path.
  tenant = if self.class.excluded_subdomains.include?(request_subdomain)
    nil
  else
    request_subdomain
  end

  tenant.presence
end