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, #deprecation_warning, #initialize, #parse_database_name, #parse_method

Constructor Details

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

Class Method Details

.excluded_subdomainsObject



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

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

.excluded_subdomains=(arg) ⇒ Object



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

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

Instance Method Details

#parse_tenant_name(request) ⇒ Object



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

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