<commit_before>require 'delegate'

module ActiveRecord
  # = Active Record Schema Dumper
  #
  # This class is used to dump the database schema for some connection to some
  # output format (i.e., ActiveRecord::Schema).
  class SchemaDumper

    private
    class TableSorter < SimpleDelegator
      def columns(table)
        __getobj__.columns(table).sort_by(&:name)
      end

      def indexes(table)
        __getobj__.indexes(table).sort_by(&:name)
      end

      def foreign_keys(table)
        __getobj__.indexes(table).sort_by(&:name)
      end
    end

    def table_with_sorting(table, stream)
      old_connection = @connection
      @connection = TableSorter.new(old_connection)
      result = table_without_sorting(table, stream)
      @connection = old_connection
      result
    end
    alias_method_chain :table, :sorting

  end
end
<commit_msg>Add support for sorting of extensions<commit_after>require 'delegate'

module ActiveRecord
  # = Active Record Schema Dumper
  #
  # This class is used to dump the database schema for some connection to some
  # output format (i.e., ActiveRecord::Schema).
  class SchemaDumper

    private
    class ConnectionWithSorting < SimpleDelegator
      def extensions
        __getobj__.extensions.sort
      end

      def columns(table)
        __getobj__.columns(table).sort_by(&:name)
      end

      def indexes(table)
        __getobj__.indexes(table).sort_by(&:name)
      end

      def foreign_keys(table)
        __getobj__.indexes(table).sort_by(&:name)
      end
    end

    def extensions_with_sorting(*args)
      with_sorting do
        extensions_without_sorting(*args)
      end
    end
    alias_method_chain :extensions, :sorting

    def table_with_sorting(*args)
      with_sorting do
        table_without_sorting(*args)
      end
    end
    alias_method_chain :table, :sorting

    def with_sorting(&block)
      old, @connection = @connection, ConnectionWithSorting.new(@connection)
      result = yield
      @connection = old
      result
    end
  end
end

{'fraction_non_alphanumeric': 0.07436399217221135, 'fraction_numerical': 0.0, 'mean_word_length': 2.8295880149812733, 'pattern_counts': {'":': 0, '<': 5, '<?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': '4219742', 'n_tokens_mistral': 611, 'n_tokens_neox': 595, 'n_words': 152}