Class: Apartment::Elevators::Host

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

Overview

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

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

.ignored_first_subdomainsObject



15
16
17
# File 'lib/apartment/elevators/host.rb', line 15

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

.ignored_first_subdomains=(arg) ⇒ Object



19
20
21
# File 'lib/apartment/elevators/host.rb', line 19

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

Instance Method Details

#parse_tenant_name(request) ⇒ Object



23
24
25
26
27
# 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