<commit_before>require 'active_support/core_ext/array/wrap'
require 'active_support/core_ext/object/blank'

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"

        next if [:where, :having, :select].include?(query_method)
        class_eval <<-CEVAL, __FILE__, __LINE__ + 1
          def #{query_method}(*args, &block)
            new_relation = clone
            new_relation.send(:apply_modules, Module.new(&block)) if block_given?
            value = Array.wrap(args.flatten).reject {|x| x.blank? }
            new_relation.#{query_method}_values += value if value.present?
            new_relation
          end
        CEVAL
      end

      class_eval <<-CEVAL, __FILE__, __LINE__ + 1
        def select(*args)
          if block_given?
            to_a.select { |*block_args| yield(*block_args) }
          else
            new_relation = clone
            value = Array.wrap(args.flatten).reject {|x| x.blank? }
            new_relation.select_values += value if value.present?
            new_relation
          end
        end
      CEVAL

      [:where, :having].each do |query_method|
        class_eval <<-CEVAL, __FILE__, __LINE__ + 1
          def #{query_method}(*args, &block)
            new_relation = clone
            new_relation.send(:apply_modules, Module.new(&block)) if block_given?
            value = build_where(*args)
            new_relation.#{query_method}_values += Array.wrap(value) if value.present?
            new_relation
          end
        CEVAL
      end

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

        class_eval <<-CEVAL, __FILE__, __LINE__ + 1
          def #{query_method}(value = true, &block)
            new_relation = clone
            new_relation.send(:apply_modules, Module.new(&block)) if block_given?
            new_relation.#{query_method}_value = value
            new_relation
          end
        CEVAL
      end
    end

    def extending(*modules)<commit_msg>Metaprogramming not needed here<commit_after>require 'active_support/core_ext/array/wrap'
require 'active_support/core_ext/object/blank'

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"

        next if [:where, :having, :select].include?(query_method)
        class_eval <<-CEVAL, __FILE__, __LINE__ + 1
          def #{query_method}(*args, &block)
            new_relation = clone
            new_relation.send(:apply_modules, Module.new(&block)) if block_given?
            value = Array.wrap(args.flatten).reject {|x| x.blank? }
            new_relation.#{query_method}_values += value if value.present?
            new_relation
          end
        CEVAL
      end

      def select(*args)
        if block_given?
          to_a.select { |*block_args| yield(*block_args) }
        else
          new_relation = clone
          value = Array.wrap(args.flatten).reject {|x| x.blank? }
          new_relation.select_values += value if value.present?
          new_relation
        end
      end

      [:where, :having].each do |query_method|
        class_eval <<-CEVAL, __FILE__, __LINE__ + 1
          def #{query_method}(*args, &block)
            new_relation = clone
            new_relation.send(:apply_modules, Module.new(&block)) if block_given?
            value = build_where(*args)
            new_relation.#{query_method}_values += Array.wrap(value) if value.present?
            new_relation
          end
        CEVAL
      end

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

        class_eval <<-CEVAL, __FILE__, __LINE__ + 1
          def #{query_method}(value = true, &block)
            new_relation = clone
            new_relation.send(:apply_modules, Module.new(&block)) if block_given?
            new_relation.#{query_method}_value = value
            new_relation
          end
        CEVAL
      end
    end

    def extending(*modules)
{'fraction_non_alphanumeric': 0.10004568296025583, 'fraction_numerical': 0.0015989036089538603, 'mean_word_length': 2.358128834355828, 'pattern_counts': {'":': 0, '<': 17, '<?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': '3830854', 'n_tokens_mistral': 1289, 'n_tokens_neox': 1264, 'n_words': 262}