Sha256: 922c292490bfd0645f0d73ec42bc685bcec40e8a73ff87c13d404f41a73e7a86

Contents?: true

Size: 972 Bytes

Versions: 6

Compression:

Stored size: 972 Bytes

Contents

require 'apartment/elevators/generic'

module Apartment
  module Elevators
    #   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 Host < Generic
      def self.ignored_first_subdomains
        @ignored_first_subdomains ||= []
      end

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

      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
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
ros-apartment-2.3.0 lib/apartment/elevators/host.rb
ros-apartment-2.3.0.alpha2 lib/apartment/elevators/host.rb
ros-apartment-2.3.0.alpha1 lib/apartment/elevators/host.rb
apartment-2.2.1 lib/apartment/elevators/host.rb
apartment-2.2.0 lib/apartment/elevators/host.rb
apartment-2.1.0 lib/apartment/elevators/host.rb