Sha256: 51b39d282911bc08a1bce0754d6ecfb185f042de74897cd6706f7b4d8fcfc982

Contents?: true

Size: 908 Bytes

Versions: 11

Compression:

Stored size: 908 Bytes

Contents

require "active_record/connection_adapters/postgresql_adapter"

module ActiveRecord
  module PGEnum
    register :type_map do
      ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.prepend InitializeTypeMap
    end

    module InitializeTypeMap
      private

      def initialize_type_map(type_map)
        super

        adapter = ConnectionAdapters::PostgreSQLAdapter

        adapter::OID.register_type "enum", adapter::OID::Enum.new

        execute("SELECT t.oid, t.typname, t.typtype FROM pg_type as t WHERE t.typtype = 'e'", "SCHEMA").each do |row|
          adapter::OID.alias_type row["typname"], "enum"
        end
      end
    end
  end

  module ConnectionAdapters
    class PostgreSQLAdapter
      module OID
        class Enum < Type
          def type
            :enum
          end

          def type_cast(value)
            value
          end
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
activerecord-pg_enum-2.0.0 lib/active_record/pg_enum/4.1/initialize_type_map.rb
activerecord-pg_enum-1.2.2 lib/active_record/pg_enum/4.1/initialize_type_map.rb
activerecord-pg_enum-1.2.1 lib/active_record/pg_enum/4.1/initialize_type_map.rb
activerecord-pg_enum-1.2.0 lib/active_record/pg_enum/4.1/initialize_type_map.rb
activerecord-pg_enum-1.1.0 lib/active_record/pg_enum/4.1/initialize_type_map.rb
activerecord-pg_enum-1.0.5 lib/active_record/pg_enum/4.1/initialize_type_map.rb
activerecord-pg_enum-1.0.4 lib/active_record/pg_enum/4.1/initialize_type_map.rb
activerecord-pg_enum-1.0.3 lib/active_record/pg_enum/4.1/initialize_type_map.rb
activerecord-pg_enum-1.0.2 lib/active_record/pg_enum/4.1/initialize_type_map.rb
activerecord-pg_enum-1.0.1 lib/active_record/pg_enum/4.1/initialize_type_map.rb
activerecord-pg_enum-1.0.0 lib/active_record/pg_enum/4.1/initialize_type_map.rb