Class: Dumbo::EnumType
Instance Attribute Summary collapse
-
#labels ⇒ Object
Returns the value of attribute labels.
Attributes inherited from Type
Attributes inherited from PgObject
Instance Method Summary collapse
Methods inherited from Type
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
#labels ⇒ Object
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_attributes ⇒ Object
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_sql ⇒ Object
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}/, '') |