Class: Apartment::Elevators::Host
- 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
- .ignored_first_subdomains ⇒ Object
-
.ignored_first_subdomains=(arg) ⇒ Object
rubocop:disable Style/TrivialAccessors.
Instance Method Summary collapse
-
#parse_tenant_name(request) ⇒ Object
rubocop:enable Style/TrivialAccessors.
Methods inherited from Generic
Constructor Details
This class inherits a constructor from Apartment::Elevators::Generic
Class Method Details
.ignored_first_subdomains ⇒ Object
17 18 19 |
# File 'lib/apartment/elevators/host.rb', line 17 def self.ignored_first_subdomains @ignored_first_subdomains ||= [] end |
.ignored_first_subdomains=(arg) ⇒ Object
rubocop:disable Style/TrivialAccessors
22 23 24 |
# File 'lib/apartment/elevators/host.rb', line 22 def self.ignored_first_subdomains=(arg) @ignored_first_subdomains = arg end |
Instance Method Details
#parse_tenant_name(request) ⇒ Object
rubocop:enable Style/TrivialAccessors
27 28 29 30 31 32 |
# File 'lib/apartment/elevators/host.rb', line 27 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 |