<commit_before>module Paginative
  module OrderingHelpers
    extend ActiveSupport::Concern

    def sanitized_ordering(table_name, field, order)
      "#{table_name}.#{sanitize_column(field)} #{sanitize_column_direction(order)}"
    end

    private
    def sanitize_column(column)
      resource.column_names.include?(column) ? column : "created_at"
    end

    def sanitize_column_direction(direction)
      direction = direction.upcase
      ['DESC', 'ASC'].include?(direction) ? direction : "DESC"
    end

    def resource
      controller_name.camelize.singularize.safe_constantize
    end
  end<commit_msg>Adding the new ordering helpers<commit_after>module Paginative
  module OrderingHelpers
    extend ActiveSupport::Concern

    def sanitized_ordering(table_name, field, order)
      if field.is_a? Array
        return raise "Wrong number of sorting fields. Expected 2, got #{field.length}. If you want to sort by a singular field please pass field argument as a string rather than an array." unless field.length == 2
        "'#{table_name}.#{sanitize_column(field[0])} || #{table_name}.#{sanitize_column(field[1])}' #{sanitize_column_direction(order)}"
      else
        "#{table_name}.#{sanitize_column(field)} #{sanitize_column_direction(order)}"
      end
    end

    private
    def sanitize_column(column)
      resource.column_names.include?(column) ? column : "created_at"
    end

    def sanitize_column_direction(direction)
      direction = direction.upcase
      ['DESC', 'ASC'].include?(direction) ? direction : "DESC"
    end

    def resource
      controller_name.camelize.singularize.safe_constantize
    end
  end
{'fraction_non_alphanumeric': 0.09945421467556094, 'fraction_numerical': 0.002425712553062462, 'mean_word_length': 3.838709677419355, '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': '2354223', 'n_tokens_mistral': 492, 'n_tokens_neox': 490, 'n_words': 113}