Class: ActiveRecord::ConnectionAdapters::PostGIS::TableDefinition

Inherits:
PostgreSQL::TableDefinition
  • Object
show all
Includes:
ColumnMethods
Defined in:
lib/active_record/connection_adapters/postgis/spatial_table_definition.rb

Overview

:nodoc:

Instance Method Summary collapse

Methods included from ColumnMethods

#geography, #geometry, #geometry_collection, #line_string, #multi_line_string, #multi_point, #multi_polygon, #spatial, #st_point, #st_polygon

Instance Method Details

#new_column_definition(name, type, **options) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/active_record/connection_adapters/postgis/spatial_table_definition.rb', line 10

def new_column_definition(name, type, **options)
  col_type = if type.to_sym == :virtual
    options[:type]
  else
    type
  end

  if (info = PostGISAdapter.spatial_column_options(col_type))
    if (limit = options.delete(:limit)) && limit.is_a?(::Hash)
      options.merge!(limit)
    end

    geo_type = ColumnDefinitionUtils.geo_type(options[:type] || type || info[:type])
    base_type = info[:type] || (options[:geographic] ? :geography : :geometry)

    options[:limit] = ColumnDefinitionUtils.limit_from_options(geo_type, options)
    options[:spatial_type] = geo_type
    column = super(name, base_type, **options)
  else
    column = super(name, type, **options)
  end

  column
end