Class: Dumbo::EnumType

Inherits:
Type show all
Defined in:
lib/dumbo/enum_type.rb

Instance Attribute Summary collapse

Attributes inherited from Type

#name, #type, #typrelid

Attributes inherited from PgObject

#oid

Instance Method Summary collapse

Methods inherited from Type

#drop, #get

Methods inherited from PgObject

#downgrade, #execute, #get, identfied_by, #identify, #initialize, #upgrade

Constructor Details

This class inherits a constructor from Dumbo::PgObject

Instance Attribute Details

#labelsObject

Returns the value of attribute labels.



3
4
5
# File 'lib/dumbo/enum_type.rb', line 3

def labels
  @labels
end

Instance Method Details

#load_attributesObject



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/dumbo/enum_type.rb', line 6

def load_attributes
  super

  res = execute "      SELECT enumlabel\n      FROM pg_enum\n      WHERE enumtypid = \#{oid}\n      ORDER by enumsortorder\n    SQL\n    @labels = res.to_a.map{|r| r['enumlabel']}\nend\n"

#to_sqlObject



18
19
20
21
22
23
24
25
26
# File 'lib/dumbo/enum_type.rb', line 18

def to_sql
    lbl_str = labels.map{|l| "'"+l+"'"}.join(",\n  ")

    "    CREATE TYPE \#{name} AS ENUM (\n      \#{lbl_str}\n    );\n    SQL\nend\n".gsub(/^ {6}/, '')