class Apartment::Elevators::Host

Provides a rack based tenant switching solution based on the host Assumes that tenant name should match host Strips/ignores first subdomains in ignored_first_subdomains eg. example.com => example.com

www.example.bc.ca => www.example.bc.ca

if ignored_first_subdomains = ['www']

www.example.bc.ca => example.bc.ca
www.a.b.c.d.com   => a.b.c.d.com

Public Class Methods

ignored_first_subdomains() click to toggle source
# File lib/apartment/elevators/host.rb, line 15
def self.ignored_first_subdomains
  @ignored_first_subdomains ||= []
end
ignored_first_subdomains=(arg) click to toggle source
# File lib/apartment/elevators/host.rb, line 19
def self.ignored_first_subdomains=(arg)
  @ignored_first_subdomains = arg
end

Public Instance Methods

parse_tenant_name(request) click to toggle source
# File lib/apartment/elevators/host.rb, line 23
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