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
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/dumbo/enum_type.rb', line 5 def load_attributes super res = execute <<-SQL SELECT enumlabel FROM pg_enum WHERE enumtypid = #{oid} ORDER by enumsortorder SQL @labels = res.to_a.map { |r| r['enumlabel'] } end |
#to_sql ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/dumbo/enum_type.rb', line 17 def to_sql lbl_str = labels.map { |l| "'" + l + "'" }.join(",\n ") <<-SQL.gsub(/^ {6}/, '') CREATE TYPE #{name} AS ENUM ( #{lbl_str} ); SQL end |