Class: Apartment::Elevators::Host

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

Overview

Tenant from full hostname. Optionally strips ignored first subdomains (e.g., www).

Instance Method Summary collapse

Methods inherited from Generic

#call

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: [], **_options)
  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