class Apartment::Elevators::Host
=> a.b.c.d.com
=> example.bc.ca
if ignored_first_subdomains = [‘www’]
=> www.example.bc.ca<br>eg. example.com => example.com
Strips/ignores first subdomains in ignored_first_subdomains
Assumes that tenant name should match host
Provides a rack based tenant switching solution based on the host
def self.ignored_first_subdomains
def self.ignored_first_subdomains @ignored_first_subdomains ||= [] end
def self.ignored_first_subdomains=(arg)
def self.ignored_first_subdomains=(arg) @ignored_first_subdomains = arg end
def parse_tenant_name(request)
def parse_tenant_name(request) return nil if request.host.blank? parts = request.host.split('.') self.class.ignored_first_subdomains.include?(parts[0]) ? parts.drop(1).join('.') : request.host end