<commit_before>module ActsAsTenant
  module ControllerExtensions
    
    # this method allows setting the current_tenant by reading the subdomain and looking
    # it up in the tenant-model passed to the method (defaults to Account). The method will 
    # look for the subdomain in a column referenced by the second argument (defaults to subdomain).
    def set_current_tenant_by_subdomain(tenant = :account, column = :subdomain )
      self.class_eval do
        cattr_accessor :tenant_class, :tenant_column
        attr_accessor :current_tenant
      end

      self.tenant_class = tenant.to_s.camelcase.constantize
      self.tenant_column = column.to_sym

      self.class_eval do
        before_filter :find_tenant_by_subdomain

        helper_method :current_tenant
        
        private
          def find_tenant_by_subdomain
            ActsAsTenant.current_tenant = tenant_class.where(tenant_column => request.subdomains.first).first
            @current_tenant_instance = ActsAsTenant.current_tenant
          end
          
          # helper method to have the current_tenant available in the controller  
          def current_tenant
            ActsAsTenant.current_tenant
          end
      end
    end
    
    # This method sets up a method that allows manual setting of the current_tenant. This method should
    # be used in a before_filter. In addition, a helper is setup that returns the current_tenant
    def set_current_tenant_through_filter
      self.class_eval do
        helper_method :current_tenant
        
        def set_current_tenant(current_tenant_object)
          ActsAsTenant.current_tenant = current_tenant_object
        end
        
        private
          # helper method to have the current_tenant available in the controller  
          def current_tenant
            ActsAsTenant.current_tenant
          end
      end
    end
    
    
    
    # this method allows manual setting of the current_tenant by passing in a tenant object
    # 
    def set_current_tenant_to(current_tenant_object)
      self.class_eval do
        cattr_accessor :tenant_class
        attr_accessor :current_tenant
        before_filter lambda { 
          ActiveSupport::Deprecation.warn "set_current_tenant_to is deprecated and will be removed from Acts_as_tenant in a future releases, please use set_current_tenant_through_filter instead.", caller
          @current_tenant_instance = ActsAsTenant.current_tenant = current_tenant_object 
          }
        
        helper_method :current_tenant
        
        private
          # helper method to have the current_tenant available in the controller  
          def current_tenant
            ActsAsTenant.current_tenant<commit_msg>add method call for use in ApplicationController<commit_after>module ActsAsTenant
  module ControllerExtensions
    
    # this method allows setting the current_tenant by reading the subdomain and looking
    # it up in the tenant-model passed to the method (defaults to Account). The method will 
    # look for the subdomain in a column referenced by the second argument (defaults to subdomain).
    def set_current_tenant_by_subdomain(tenant = :account, column = :subdomain )
      self.class_eval do
        cattr_accessor :tenant_class, :tenant_column
        attr_accessor :current_tenant
      end

      self.tenant_class = tenant.to_s.camelcase.constantize
      self.tenant_column = column.to_sym

      self.class_eval do
        before_filter :find_tenant_by_subdomain

        helper_method :current_tenant
        
        private
          def find_tenant_by_subdomain
            ActsAsTenant.current_tenant = tenant_class.where(tenant_column => request.subdomains.first).first
            @current_tenant_instance = ActsAsTenant.current_tenant
          end
          
          # helper method to have the current_tenant available in the controller  
          def current_tenant
            ActsAsTenant.current_tenant
          end
      end
    end
    
    # This method sets up a method that allows manual setting of the current_tenant. This method should
    # be used in a before_filter. In addition, a helper is setup that returns the current_tenant
    def set_current_tenant_through_filter
      self.class_eval do
        helper_method :current_tenant
        
        def set_current_tenant(current_tenant_object)
          ActsAsTenant.current_tenant = current_tenant_object
        end
        
        private
          # helper method to have the current_tenant available in the controller  
          def current_tenant
            ActsAsTenant.current_tenant
          end
      end
    end

    def require_tenant
      ActsAsTenant.require_tenant
    end
    
    # this method allows manual setting of the current_tenant by passing in a tenant object
    # 
    def set_current_tenant_to(current_tenant_object)
      self.class_eval do
        cattr_accessor :tenant_class
        attr_accessor :current_tenant
        before_filter lambda { 
          ActiveSupport::Deprecation.warn "set_current_tenant_to is deprecated and will be removed from Acts_as_tenant in a future releases, please use set_current_tenant_through_filter instead.", caller
          @current_tenant_instance = ActsAsTenant.current_tenant = current_tenant_object 
          }
        
        helper_method :current_tenant
        
        private
          # helper method to have the current_tenant available in the controller  
          def current_tenant
            ActsAsTenant.current_tenant
{'fraction_non_alphanumeric': 0.03198987890836798, 'fraction_numerical': 0.0, 'mean_word_length': 2.5315890236119976, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '1679789', 'n_tokens_mistral': 1421, 'n_tokens_neox': 1481, 'n_words': 439}