Class: ActiveRecord::ConnectionAdapters::PostgreSQLIndexDefinition
- Inherits:
-
Object
- Object
- ActiveRecord::ConnectionAdapters::PostgreSQLIndexDefinition
- Defined in:
- lib/active_record/postgresql_extensions/indexes.rb
Overview
Creates a PostgreSQL index definition. This class isn’t really meant to be used directly. Instead, see PostgreSQLAdapter#create_index for usage.
Instance Attribute Summary collapse
-
#base ⇒ Object
Returns the value of attribute base.
-
#columns ⇒ Object
Returns the value of attribute columns.
-
#name ⇒ Object
Returns the value of attribute name.
-
#object ⇒ Object
Returns the value of attribute object.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(base, name, object, columns, options = {}) ⇒ PostgreSQLIndexDefinition
constructor
:nodoc:.
-
#to_sql ⇒ Object
(also: #to_s)
:nodoc:.
Constructor Details
#initialize(base, name, object, columns, options = {}) ⇒ PostgreSQLIndexDefinition
:nodoc:
172 173 174 175 176 177 |
# File 'lib/active_record/postgresql_extensions/indexes.rb', line 172 def initialize(base, name, object, columns, = {}) #:nodoc: assert_valid_columns(columns) assert_valid_fill_factor([:fill_factor]) @base, @name, @object, @columns, @options = base, name, object, columns, end |
Instance Attribute Details
#base ⇒ Object
Returns the value of attribute base.
170 171 172 |
# File 'lib/active_record/postgresql_extensions/indexes.rb', line 170 def base @base end |
#columns ⇒ Object
Returns the value of attribute columns.
170 171 172 |
# File 'lib/active_record/postgresql_extensions/indexes.rb', line 170 def columns @columns end |
#name ⇒ Object
Returns the value of attribute name.
170 171 172 |
# File 'lib/active_record/postgresql_extensions/indexes.rb', line 170 def name @name end |
#object ⇒ Object
Returns the value of attribute object.
170 171 172 |
# File 'lib/active_record/postgresql_extensions/indexes.rb', line 170 def object @object end |
#options ⇒ Object
Returns the value of attribute options.
170 171 172 |
# File 'lib/active_record/postgresql_extensions/indexes.rb', line 170 def @options end |
Instance Method Details
#to_sql ⇒ Object Also known as: to_s
:nodoc:
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
# File 'lib/active_record/postgresql_extensions/indexes.rb', line 179 def to_sql #:nodoc: sql = 'CREATE ' sql << 'UNIQUE ' if [:unique] sql << 'INDEX ' sql << 'CONCURRENTLY ' if [:concurrently] sql << "#{base.quote_generic(name)} ON #{base.quote_table_name(object)}" sql << " USING #{base.quote_generic([:using])}" if [:using] sql << '(' sql << [ columns ].flatten.collect do |column| column_def = String.new if column.is_a?(Hash) column_def << if column[:column] "#{base.quote_column_name(column[:column])}" else "(#{column[:expression]})" end column_def << " #{base.quote_generic(column[:opclass])}" if column[:opclass] column_def << " #{column[:order].to_s.upcase}" if column[:order] column_def << " NULLS #{column[:nulls].to_s.upcase}" if column[:nulls] column_def else base.quote_column_name(column.to_s) end end.join(', ') sql << ')' sql << " WITH (FILLFACTOR = #{[:fill_factor].to_i})" if [:fill_factor] sql << " WITH (#{ActiveRecord::PostgreSQLExtensions::Utils.([:index_parameters], base)})" if [:index_parameters].present? sql << " TABLESPACE #{base.quote_tablespace([:tablespace])}" if [:tablespace] sql << " WHERE (#{[:conditions] || [:where]})" if [:conditions] || [:where] "#{sql};" end |