Class: ActiveRecord::ConnectionAdapters::SpatiaLiteAdapter::SpatialTableDefinition

Inherits:
ConnectionAdapters::TableDefinition
  • Object
show all
Defined in:
lib/active_record/connection_adapters/spatialite_adapter/spatial_table_definition.rb

Instance Method Summary collapse

Instance Method Details

#column(name_, type_, options_ = {}) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/active_record/connection_adapters/spatialite_adapter/spatial_table_definition.rb', line 48

def column(name_, type_, options_={})
  if (info_ = @base.spatial_column_constructor(type_.to_sym))
    options_[:type] ||= info_[:type] || type_
    type_ = :spatial
  end
  super(name_, type_, options_)
  if type_ == :spatial
    col_ = self[name_]
    col_.extend(SpatialColumnDefinitionMethods) unless col_.respond_to?(:srid)
    options_.merge!(col_.limit) if col_.limit.is_a?(::Hash)
    col_.set_spatial_type(options_[:type])
    col_.set_srid(options_[:srid].to_i)
  end
  self
end

#spatial_columnsObject



68
69
70
# File 'lib/active_record/connection_adapters/spatialite_adapter/spatial_table_definition.rb', line 68

def spatial_columns
  @columns.find_all{ |c_| c_.respond_to?(:srid) }
end

#to_sqlObject



64
65
66
# File 'lib/active_record/connection_adapters/spatialite_adapter/spatial_table_definition.rb', line 64

def to_sql
  @columns.find_all{ |c_| !c_.respond_to?(:srid) }.map{ |c_| c_.to_sql } * ', '
end