<commit_before>module HeySorty
  module NamedScope
    def self.included(base)
      base.extend(ClassMethods)
    end
  
    module ClassMethods
      def sortable(column = :id, order = :asc)
        # Defaults
        @options = { :column => column.to_s, :order => order.to_s }
        
        # Available options
        valid_orders = %w[asc desc]
        valid_columns = columns.map(&:name)
        valid_columns += reflections.map{|r| r[1].class_name.constantize.columns.map{|c| "#{r[0]}.#{c.name}"}}.flatten
               
        # Check arguments
        raise InvalidColumnName unless valid_columns.include?(@options[:column])
        raise InvalidOrderValue unless valid_orders.include?(@options[:order])
      
        # Define named scope
        named_scope :sorty, lambda { |params|
          # Sorting attributes
          column = params[:column] || @options[:column]
          order = params[:order] || @options[:order]
          
          # Check for errors
          raise ArgumentError unless valid_columns.include?(column) && valid_orders.include?(order)
          
          # Load in association
          if column.include?('.')
            # Split column into reflection name and column
            reflection_name, column = column.split('.')
            reflection_name = reflection_name.to_sym
            
            # Calculate the new column name
            table = reflections[reflection_name].table_name
            column = "#{table}.#{column}"
            
            # Add the association
            associations = [reflection_name]
          end
        
          # Return order hash
          { :order => [column, order].delete_if(&:blank?).join(' '), :include => associations } <commit_msg>Ignoring polymorphic associations<commit_after>module HeySorty
  module NamedScope
    def self.included(base)
      base.extend(ClassMethods)
    end
  
    module ClassMethods
      def sortable(column = :id, order = :asc)
        # Defaults
        @options = { :column => column.to_s, :order => order.to_s }
        
        # Available options
        valid_orders = %w[asc desc]
        valid_columns = columns.map(&:name)
        valid_columns += reflections.map{|r| r[1].options[:polymorphic] === true ? nil : r[1].class_name.constantize.columns.map{|c| "#{r[0]}.#{c.name}"}}.flatten
               
        # Check arguments
        raise InvalidColumnName unless valid_columns.include?(@options[:column])
        raise InvalidOrderValue unless valid_orders.include?(@options[:order])
      
        # Define named scope
        named_scope :sorty, lambda { |params|
          # Sorting attributes
          column = params[:column] || @options[:column]
          order = params[:order] || @options[:order]
          
          # Check for errors
          raise ArgumentError unless valid_columns.include?(column) && valid_orders.include?(order)
          
          # Load in association
          if column.include?('.')
            # Split column into reflection name and column
            reflection_name, column = column.split('.')
            reflection_name = reflection_name.to_sym
            
            # Calculate the new column name
            table = reflections[reflection_name].table_name
            column = "#{table}.#{column}"
            
            # Add the association
            associations = [reflection_name]
          end
        
          # Return order hash
          { :order => [column, order].delete_if(&:blank?).join(' '), :include => associations } 
{'fraction_non_alphanumeric': 0.10938383267382702, 'fraction_numerical': 0.0014132278123233466, 'mean_word_length': 2.077391304347826, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '5872760', 'n_tokens_mistral': 926, 'n_tokens_neox': 919, 'n_words': 215}