<commit_before>module MultiTenancy
  module Tenant
    extend ActiveSupport::Concern

    included do
    end

    module ClassMethods
      def acts_as_tenant(options = {})
        has_many :users, dependent: :destroy
        accepts_nested_attributes_for :users

        validates :name, :subdomain,
                  presence: true, uniqueness: true

        validates :domain,
                  uniqueness: true

        validates_associated :users
        validates_presence_of :users, on: :save

        include MultiTenancy::Tenant::LocalInstanceMethods
      end
    end

    module LocalInstanceMethods
      def to_s
        subdomain || domain
      end
    end

    def self.tenant_class
      Rails.application.config.tenant_class
    end

    def self.tenant_column
      Rails.application.config.tenant_column
    end

    def self.current_id=(id)
      Thread.current[Rails.application.config.tenant_column] = id
    end

    def self.current_id
      Thread.current[Rails.application.config.tenant_column]
    end

    def self.current
      self.tenant_class.find_by_id(self.current_id)
    end

    def self.find_by_id(id)
      self.tenant_class.find_by_id(id)
    end

    def self.find_by_id!(id)
      self.tenant_class.find_by_id(id)
    end

    def self.find_by_domain(domain)
      self.tenant_class.find_by_domain(domain)
    end

    def self.find_by_domain!(domain)
      self.tenant_class.find_by_domain!(domain)
    end

    def self.find_by_subdomain!(subdomain)
      self.tenant_class.find_by_subdomain!(subdomain)
    end

    def self.current_user_tenant_id
      current_user.present? ? current_user.send(self.tenant_column) : nil
    end    
  end
end
 
ActiveRecord::Base.send :include, MultiTenancy::Tenant<commit_msg>add missing find_by_subdomain<commit_after>module MultiTenancy
  module Tenant
    extend ActiveSupport::Concern

    included do
    end

    module ClassMethods
      def acts_as_tenant(options = {})
        has_many :users, dependent: :destroy
        accepts_nested_attributes_for :users

        validates :name, :subdomain,
                  presence: true, uniqueness: true

        validates :domain,
                  uniqueness: true

        validates_associated :users
        validates_presence_of :users, on: :save

        include MultiTenancy::Tenant::LocalInstanceMethods
      end
    end

    module LocalInstanceMethods
      def to_s
        subdomain || domain
      end
    end

    def self.tenant_class
      Rails.application.config.tenant_class
    end

    def self.tenant_column
      Rails.application.config.tenant_column
    end

    def self.current_id=(id)
      Thread.current[Rails.application.config.tenant_column] = id
    end

    def self.current_id
      Thread.current[Rails.application.config.tenant_column]
    end

    def self.current
      self.tenant_class.find_by_id(self.current_id)
    end

    def self.find_by_id(id)
      self.tenant_class.find_by_id(id)
    end

    def self.find_by_id!(id)
      self.tenant_class.find_by_id(id)
    end

    def self.find_by_domain(domain)
      self.tenant_class.find_by_domain(domain)
    end

    def self.find_by_domain!(domain)
      self.tenant_class.find_by_domain!(domain)
    end

    def self.find_by_subdomain(subdomain)
      self.tenant_class.find_by_subdomain(subdomain)
    end

    def self.find_by_subdomain!(subdomain)
      self.tenant_class.find_by_subdomain!(subdomain)
    end

    def self.current_user_tenant_id
      current_user.present? ? current_user.send(self.tenant_column) : nil
    end    
  end
end
 
ActiveRecord::Base.send :include, MultiTenancy::Tenant
{'fraction_non_alphanumeric': 0.07009345794392523, 'fraction_numerical': 0.0, 'mean_word_length': 2.68693009118541, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '2822568', 'n_tokens_mistral': 1159, 'n_tokens_neox': 1148, 'n_words': 205}