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



12
13
14
# File 'lib/apartment/elevators/subdomain.rb', line 12

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

.excluded_subdomains=(arg) ⇒ Object

rubocop:disable Style/TrivialAccessors



17
18
19
# File 'lib/apartment/elevators/subdomain.rb', line 17

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

Instance Method Details

#parse_tenant_name(request) ⇒ Object

rubocop:enable Style/TrivialAccessors



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/apartment/elevators/subdomain.rb', line 22

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