<commit_before>module IndexTanked

  class CustomDocIdNotSupportedError < IndexTankedError; end

  module ActiveRecordDefaults
    class ClassCompanion < IndexTanked::ClassCompanion

      attr_reader :model

      def initialize(model, options)
        @model = model
        super(options)
      end

      def add_fields_to_query(query, options={})
        [super, "model:#{@model.name}"].compact.join(" ")
      end

      def doc_id
        raise CustomDocIdNotSupportedError
      end

      def doc_id_value
        lambda { |instance| "#{instance.class.name}:#{instance.id}"}
      end

      def dependent_fields
        if !@dependent_fields
          @dependent_fields = @fields.map do |field|
            field[2][:depends_on] || field[1]
          end.flatten.compact.uniq

          if !@dependent_fields.include?(:created_at) && model.column_names.include?("created_at")
            @dependent_fields << :created_at
          end
        end

        @dependent_fields
      end

      def dependent_fields_as_strings
        @dependent_fields_as_strings ||= dependent_fields.map(&:to_s)
      end

      def dependent_fields_for_select(*additional_fields)
        fields = if additional_fields.empty?
          dependent_fields_as_strings
        else
          (dependent_fields_as_strings + additional_fields.map(&:to_s)).uniq
        end
        fields.join(', ')
      end

      def retry_on_error(options={}, &block)
        times            = options[:times] || 3
        delay_multiplier = options[:delay_multiplier] || 0
        excepts          = [options[:except]].compact.flatten
        count            = 0
        begin
          instance_eval(&block)
        rescue Timeout::Error, StandardError => e
          if excepts.include?(e.class)
            raise e
          else
            retry if times == :infinity
            count += 1
            sleep count * delay_multiplier<commit_msg>yield instead of instance_eval in retry_on_error to maintain scope<commit_after>module IndexTanked

  class CustomDocIdNotSupportedError < IndexTankedError; end

  module ActiveRecordDefaults
    class ClassCompanion < IndexTanked::ClassCompanion

      attr_reader :model

      def initialize(model, options)
        @model = model
        super(options)
      end

      def add_fields_to_query(query, options={})
        [super, "model:#{@model.name}"].compact.join(" ")
      end

      def doc_id
        raise CustomDocIdNotSupportedError
      end

      def doc_id_value
        lambda { |instance| "#{instance.class.name}:#{instance.id}"}
      end

      def dependent_fields
        if !@dependent_fields
          @dependent_fields = @fields.map do |field|
            field[2][:depends_on] || field[1]
          end.flatten.compact.uniq

          if !@dependent_fields.include?(:created_at) && model.column_names.include?("created_at")
            @dependent_fields << :created_at
          end
        end

        @dependent_fields
      end

      def dependent_fields_as_strings
        @dependent_fields_as_strings ||= dependent_fields.map(&:to_s)
      end

      def dependent_fields_for_select(*additional_fields)
        fields = if additional_fields.empty?
          dependent_fields_as_strings
        else
          (dependent_fields_as_strings + additional_fields.map(&:to_s)).uniq
        end
        fields.join(', ')
      end

      def retry_on_error(options={})
        times            = options[:times] || 3
        delay_multiplier = options[:delay_multiplier] || 0
        excepts          = [options[:except]].compact.flatten
        count            = 0
        begin
          yield
        rescue Timeout::Error, StandardError => e
          if excepts.include?(e.class)
            raise e
          else
            retry if times == :infinity
            count += 1
            sleep count * delay_multiplier
{'fraction_non_alphanumeric': 0.08795460407531597, 'fraction_numerical': 0.003095176683002321, 'mean_word_length': 2.1426256077795784, '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': '6269489', 'n_tokens_mistral': 1100, 'n_tokens_neox': 1062, 'n_words': 220}