Sha256: 853cbf6d204eb7ef2621f91fc78b2299a76c7069cee0be1715d30e3ab49e9822

Contents?: true

Size: 1009 Bytes

Versions: 1

Compression:

Stored size: 1009 Bytes

Contents

module ActiveRecord
  module PGEnum
    module SchemaDumper
      private

      def extensions(stream)
        super
        enums(stream)
      end

      def enums(stream)
        return unless (enum_types = @connection.enum_types).any?

        stream.puts "  # These are custom enum types that must be created before they can be used in the schema definition"

        enum_types.each do |enum_type|
          stream.puts %Q{  create_enum "#{enum_type.first}", "#{enum_type.second.join("\", \"")}"}
        end

        stream.puts
      end

      def column_spec(column)
        if column.type == :enum
          ["column", [column.sql_type.inspect, prepare_column_options(column)]]
        else
          super
        end
      end

      def format_colspec(colspec)
        case colspec
        when String
          colspec
        when Array
          colspec.map { |value| format_colspec(value) }.select(&:present?).join(", ")
        else
          super
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
activerecord-pg_enum-0.0.1 lib/active_record/pg_enum/schema_dumper.rb