Class: Apartment::Elevators::Host
- Defined in:
- lib/apartment/elevators/host.rb
Overview
Tenant from full hostname. Optionally strips ignored first subdomains (e.g., www).
Instance Method Summary collapse
-
#initialize(app, ignored_first_subdomains: [], **_options) ⇒ Host
constructor
A new instance of Host.
- #parse_tenant_name(request) ⇒ Object
Methods inherited from Generic
Constructor Details
#initialize(app, ignored_first_subdomains: [], **_options) ⇒ Host
Returns a new instance of Host.
9 10 11 12 |
# File 'lib/apartment/elevators/host.rb', line 9 def initialize(app, ignored_first_subdomains: [], **) super(app) @ignored_first_subdomains = Array(ignored_first_subdomains).map(&:to_s).freeze end |
Instance Method Details
#parse_tenant_name(request) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/apartment/elevators/host.rb', line 14 def parse_tenant_name(request) return nil if request.host.blank? parts = request.host.split('.') @ignored_first_subdomains.include?(parts[0]) ? parts.drop(1).join('.') : request.host end |