<commit_before>module MultiDomains::DomainHandler

  def self.included(base)
    base.extend(ClassMethods)
  end

  module ClassMethods
    def handle_multiple_domains
      define_method("current_#{MultiDomains.domain_customizable_name}") do
        MultiDomains.domain_customizable_class.find_by(fetch_current_object_params)
      end

      if MultiDomains.force_redirect_to_https?
        before_filter :redirect_to_https
      end

      before_filter :fetch_current_object_params
      before_filter :redirect_to_standard
      helper_method "current_#{MultiDomains.domain_customizable_name}"
    end
  end

  def redirect_to_https
    if MultiDomains.protocol == 'https://' && request.protocol != MultiDomains.protocol
      redirect_to request.url.gsub!('http', 'https')
    end
  end

  def redirect_to_standard
    obj = self.send("current_#{MultiDomains.domain_customizable_name}")
    if obj.present? && obj.needs_redirect?(request.domain, request.subdomain)
      redirect_options = {status: :moved_permanently}
      redirect_options.merge!(obj.try(:default_url_params)).merge!(params: request.query_parameters)
      flash.keep if respond_to?(:flash)<commit_msg>fix bug with root domain name redirection to last object<commit_after>module MultiDomains::DomainHandler

  def self.included(base)
    base.extend(ClassMethods)
  end

  module ClassMethods
    def handle_multiple_domains
      define_method("current_#{MultiDomains.domain_customizable_name}") do
        params = fetch_current_object_params
        MultiDomains.domain_customizable_class.find_by(params) if params.present?
      end

      if MultiDomains.force_redirect_to_https?
        before_filter :redirect_to_https
      end

      before_filter :fetch_current_object_params
      before_filter :redirect_to_standard
      helper_method "current_#{MultiDomains.domain_customizable_name}"
    end
  end

  def redirect_to_https
    if MultiDomains.protocol == 'https://' && request.protocol != MultiDomains.protocol
      redirect_to request.url.gsub!('http', 'https')
    end
  end

  def redirect_to_standard
    obj = self.send("current_#{MultiDomains.domain_customizable_name}")
    if obj.present? && obj.needs_redirect?(request.domain, request.subdomain)
      redirect_options = {status: :moved_permanently}
      redirect_options.merge!(obj.try(:default_url_params)).merge!(params: request.query_parameters)
      flash.keep if respond_to?(:flash)
{'fraction_non_alphanumeric': 0.08565573770491804, 'fraction_numerical': 0.0, 'mean_word_length': 4.3766519823788546, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6326552', 'n_tokens_mistral': 725, 'n_tokens_neox': 717, 'n_words': 122}