<commit_before># frozen_string_literal: true

module DatabaseRewinder
  module InsertRecorder
    module Execute
      module WithKwargs
        def execute(sql, *, **)
          DatabaseRewinder.record_inserted_table self, sql
          super
        end
      end

      module NoKwargs
        def execute(sql, *)
          DatabaseRewinder.record_inserted_table self, sql
          super
        end
      end
    end

    module ExecQuery
      module NoKwargs
        def exec_query(sql, *)
          DatabaseRewinder.record_inserted_table self, sql
          super
        end
      end

      module WithKwargs
        def exec_query(sql, *, **)
          DatabaseRewinder.record_inserted_table self, sql
          super
        end
      end
    end

    def self.prepended(mod)
      if meth = mod.instance_method(:execute)
        if meth.parameters.any? {|type, _name| [:key, :keyreq, :keyrest].include? type }
          mod.send :prepend, Execute::WithKwargs
        else
          mod.send :prepend, Execute::NoKwargs
        end
      end
      if meth = mod.instance_method(:exec_query)
        if meth.parameters.any? {|type, _name| [:key, :keyreq, :keyrest].include? type }
          mod.send :prepend, ExecQuery::WithKwargs
        else
          mod.send :prepend, ExecQuery::NoKwargs
        end
      end
    end
  end
end

::ActiveRecord::ConnectionAdapters::SQLite3Adapter.send :prepend, DatabaseRewinder::InsertRecorder if defined? ::ActiveRecord::ConnectionAdapters::SQLite3Adapter
::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.send :prepend, DatabaseRewinder::InsertRecorder if defined? ::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
::ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter.send :prepend, DatabaseRewinder::InsertRecorder if defined? ::ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter

def (::ActiveRecord::ConnectionAdapters::AbstractAdapter).inherited(adapter)
  adapter.send :prepend, DatabaseRewinder::InsertRecorder
end<commit_msg>No need to name each default Adapter because AbstractAdapter knows its descendants<commit_after># frozen_string_literal: true

module DatabaseRewinder
  module InsertRecorder
    module Execute
      module WithKwargs
        def execute(sql, *, **)
          DatabaseRewinder.record_inserted_table self, sql
          super
        end
      end

      module NoKwargs
        def execute(sql, *)
          DatabaseRewinder.record_inserted_table self, sql
          super
        end
      end
    end

    module ExecQuery
      module NoKwargs
        def exec_query(sql, *)
          DatabaseRewinder.record_inserted_table self, sql
          super
        end
      end

      module WithKwargs
        def exec_query(sql, *, **)
          DatabaseRewinder.record_inserted_table self, sql
          super
        end
      end
    end

    def self.prepended(mod)
      if meth = mod.instance_method(:execute)
        if meth.parameters.any? {|type, _name| [:key, :keyreq, :keyrest].include? type }
          mod.send :prepend, Execute::WithKwargs
        else
          mod.send :prepend, Execute::NoKwargs
        end
      end
      if meth = mod.instance_method(:exec_query)
        if meth.parameters.any? {|type, _name| [:key, :keyreq, :keyrest].include? type }
          mod.send :prepend, ExecQuery::WithKwargs
        else
          mod.send :prepend, ExecQuery::NoKwargs
        end
      end
    end
  end
end


# Already loaded adapters (SQLite3Adapter, PostgreSQLAdapter, AbstractMysqlAdapter, and possibly another third party adapter)
::ActiveRecord::ConnectionAdapters::AbstractAdapter.descendants.each do |adapter|
  adapter.send :prepend, DatabaseRewinder::InsertRecorder unless adapter < DatabaseRewinder::InsertRecorder
end

def (::ActiveRecord::ConnectionAdapters::AbstractAdapter).inherited(adapter)
  adapter.send :prepend, DatabaseRewinder::InsertRecorder
end
{'fraction_non_alphanumeric': 0.08076131687242798, 'fraction_numerical': 0.0007716049382716049, 'mean_word_length': 2.8543111992071357, 'pattern_counts': {'":': 0, '<': 4, '<?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': '1780217', 'n_tokens_mistral': 1142, 'n_tokens_neox': 1094, 'n_words': 258}