<commit_before>module ActiveRecord
  module QueryMethods
    extend ActiveSupport::Concern

    included do
      (ActiveRecord::Relation::ASSOCIATION_METHODS + ActiveRecord::Relation::MULTI_VALUE_METHODS).each do |query_method|
        attr_accessor :"#{query_method}_values"

        class_eval <<-CEVAL
          def #{query_method}(*args)
            spawn.tap do |new_relation|
              new_relation.#{query_method}_values ||= []
              value = args.size > 1 ? [args] : Array.wrap(args)
              new_relation.#{query_method}_values += value
            end
          end
        CEVAL
      end

      ActiveRecord::Relation::SINGLE_VALUE_METHODS.each do |query_method|
        attr_accessor :"#{query_method}_value"

        class_eval <<-CEVAL
          def #{query_method}(value = true)
            spawn.tap do |new_relation|
              new_relation.#{query_method}_value = value
            end
          end
        CEVAL
      end
    end

    def lock(locks = true)
      relation = spawn
      case locks
      when String, TrueClass, NilClass
        spawn.tap {|new_relation| new_relation.lock_value = locks || true }
      else
        spawn.tap {|new_relation| new_relation.lock_value = false }
      end
    end

    def reverse_order
      relation = spawn
      relation.instance_variable_set(:@orders, nil)

      order_clause = arel.send(:order_clauses).join(', ')
      if order_clause.present?
        relation.order(reverse_sql_order(order_clause))
      else
        relation.order("#{@klass.table_name}.#{@klass.primary_key} DESC")
      end
    end

    def arel<commit_msg>Use Relation#except for reversing the order<commit_after>module ActiveRecord
  module QueryMethods
    extend ActiveSupport::Concern

    included do
      (ActiveRecord::Relation::ASSOCIATION_METHODS + ActiveRecord::Relation::MULTI_VALUE_METHODS).each do |query_method|
        attr_accessor :"#{query_method}_values"

        class_eval <<-CEVAL
          def #{query_method}(*args)
            spawn.tap do |new_relation|
              new_relation.#{query_method}_values ||= []
              value = args.size > 1 ? [args] : Array.wrap(args)
              new_relation.#{query_method}_values += value
            end
          end
        CEVAL
      end

      ActiveRecord::Relation::SINGLE_VALUE_METHODS.each do |query_method|
        attr_accessor :"#{query_method}_value"

        class_eval <<-CEVAL
          def #{query_method}(value = true)
            spawn.tap do |new_relation|
              new_relation.#{query_method}_value = value
            end
          end
        CEVAL
      end
    end

    def lock(locks = true)
      relation = spawn
      case locks
      when String, TrueClass, NilClass
        spawn.tap {|new_relation| new_relation.lock_value = locks || true }
      else
        spawn.tap {|new_relation| new_relation.lock_value = false }
      end
    end

    def reverse_order
      order_clause = arel.send(:order_clauses).join(', ')
      relation = except(:order)

      if order_clause.present?
        relation.order(reverse_sql_order(order_clause))
      else
        relation.order("#{@klass.table_name}.#{@klass.primary_key} DESC")
      end
    end

    def arel
{'fraction_non_alphanumeric': 0.09526755335601608, 'fraction_numerical': 0.0006186204763377668, 'mean_word_length': 2.2899287894201423, 'pattern_counts': {'":': 0, '<': 11, '<?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': '5447972', 'n_tokens_mistral': 964, 'n_tokens_neox': 956, 'n_words': 190}