Sha256: 074acbaf7a79ffef91252fd1c77f0b925a621f714f2932edfb6d365f601f7d77

Contents?: true

Size: 1.14 KB

Versions: 2

Compression:

Stored size: 1.14 KB

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 |name, definition|
          stream.puts %Q{  create_enum "#{name}", "#{definition.join("\", \"")}"}
        end

        stream.puts
      end

      # Gathers the arguments needed for the column line inside the create_table block.
      def column_spec(column)
        if column.type == :enum
          ["column", [column.sql_type.inspect, prepare_column_options(column)]]
        else
          super
        end
      end

      # Takes a column specification in Object form and serializes it into a String.
      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

2 entries across 2 versions & 1 rubygems

Version Path
activerecord-pg_enum-0.1.1 lib/active_record/pg_enum/schema_dumper.rb
activerecord-pg_enum-0.1.0 lib/active_record/pg_enum/schema_dumper.rb