Class: ActiveRecord::PostgreSQLEnumDefinition
- Inherits:
-
Object
- Object
- ActiveRecord::PostgreSQLEnumDefinition
- Defined in:
- lib/active_record/postgresql_extensions/types.rb
Overview
Creates a PostgreSQL enum type definition. This class isn’t really meant to be used directly. Instead, see PostgreSQLAdapter#create_enum for usage.
Instance Attribute Summary collapse
-
#base ⇒ Object
Returns the value of attribute base.
-
#name ⇒ Object
Returns the value of attribute name.
-
#values ⇒ Object
Returns the value of attribute values.
Instance Method Summary collapse
-
#initialize(base, name, *values) ⇒ PostgreSQLEnumDefinition
constructor
A new instance of PostgreSQLEnumDefinition.
-
#to_sql ⇒ Object
(also: #to_s)
:nodoc:.
Constructor Details
#initialize(base, name, *values) ⇒ PostgreSQLEnumDefinition
Returns a new instance of PostgreSQLEnumDefinition.
108 109 110 |
# File 'lib/active_record/postgresql_extensions/types.rb', line 108 def initialize(base, name, *values) @base, @name, @values = base, name, values.flatten end |
Instance Attribute Details
#base ⇒ Object
Returns the value of attribute base.
106 107 108 |
# File 'lib/active_record/postgresql_extensions/types.rb', line 106 def base @base end |
#name ⇒ Object
Returns the value of attribute name.
106 107 108 |
# File 'lib/active_record/postgresql_extensions/types.rb', line 106 def name @name end |
#values ⇒ Object
Returns the value of attribute values.
106 107 108 |
# File 'lib/active_record/postgresql_extensions/types.rb', line 106 def values @values end |
Instance Method Details
#to_sql ⇒ Object Also known as: to_s
:nodoc:
112 113 114 115 116 117 |
# File 'lib/active_record/postgresql_extensions/types.rb', line 112 def to_sql #:nodoc: sql = "CREATE TYPE #{base.quote_generic(name)} AS ENUM (" sql << values.collect { |t| base.quote(t.to_s) }.join(', ') sql << ")" "#{sql};" end |