# 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) if Rails.env.development? domain = request.env["websites.dev_domain"].presence || request.domain subdomains = request.env["websites.dev_subdomains"].presence || request.subdomains Rails.logger.info("Domain: #{@domain}; Subdomain: #{@subdomain}; Current Host: #{domain}; Current Subdomains: #{subdomains}; Matches (Domain): #{domain_matches?(request)}; Matches (Subdomain): #{subdomain_matches?(request)}") end subdomain_matches?(request) && domain_matches?(request) end private def domain_matches?(request) (Rails.env.development? && request.env["websites.dev_domain"] == @domain) || request.domain == @domain end def subdomain_matches?(request) if Rails.env.development? && !request.env["websites.dev_subdomains"].nil? return true if @subdomain.nil? && request.env["websites.dev_subdomains"].blank? return true if request.env["websites.dev_subdomains"] == @subdomain end (@subdomain.nil? && request.subdomain.blank?) || request.subdomain == @subdomain end end