Sha256: 7f73d8bc5294d93995074bdeb9f9375267b604b14be1dec66377cd5416671fb8

Contents?: true

Size: 668 Bytes

Versions: 2

Compression:

Stored size: 668 Bytes

Contents

require "active_record/connection_adapters/abstract/quoting"

module Rein
  module Type
    # This module contains methods for defining enum types.
    module Enum
      include ActiveRecord::ConnectionAdapters::Quoting

      def create_enum_type(enum_name, enum_values = [])
        enum_values = enum_values.map { |value| quote(value) }.join(", ")
        execute("CREATE TYPE #{enum_name} AS ENUM (#{enum_values})")
      end

      def drop_enum_type(enum_name)
        execute("DROP TYPE #{enum_name}")
      end

      def add_enum_value(enum_name, new_value)
        execute("ALTER TYPE #{enum_name} ADD VALUE #{quote(new_value)}")
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rein-2.1.0 lib/rein/type/enum.rb
rein-2.0.0 lib/rein/type/enum.rb