Sha256: 5a20ce8448eed98ec683f6ebe70681a90eac59d6b40139f3c52d4402a5927c47

Contents?: true

Size: 1.1 KB

Versions: 2

Compression:

Stored size: 1.1 KB

Contents

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fix-db-schema-conflicts-1.2.2 lib/fix_db_schema_conflicts/schema_dumper.rb
fix-db-schema-conflicts-1.2.1 lib/fix_db_schema_conflicts/schema_dumper.rb