Donovan Daniels
90c05547f6
This makes matching against routes later much more reliable and less complicated
28 lines
780 B
Ruby
28 lines
780 B
Ruby
# frozen_string_literal: true
|
|
|
|
class DomainConstraint
|
|
attr_reader :domain, :subdomain
|
|
|
|
DEFAULT_DOMAIN = nil # "yiff.rest"
|
|
|
|
def initialize(domain, subdomain = nil)
|
|
@domain = domain
|
|
@subdomain = subdomain
|
|
end
|
|
|
|
def matches?(request)
|
|
Rails.logger.info("Domain: #{@domain}; Subdomain: #{@subdomain}; Current Host: #{request.domain}; Current Subdomains: #{request.subdomain}; Matches (Domain): #{domain_matches?(request)}; Matches (Subdomain): #{subdomain_matches?(request)}") if Rails.env.development?
|
|
subdomain_matches?(request) && domain_matches?(request)
|
|
end
|
|
|
|
private
|
|
|
|
def domain_matches?(request)
|
|
@domain.nil? || request.domain == @domain
|
|
end
|
|
|
|
def subdomain_matches?(request)
|
|
@subdomain.nil? || request.subdomain == @subdomain
|
|
end
|
|
end
|