Class: ActiveRecord::ConnectionAdapters::PostGISAdapter::TableDefinition
- Inherits:
-
ConnectionAdapters::PostgreSQLAdapter::TableDefinition
- Object
- ConnectionAdapters::PostgreSQLAdapter::TableDefinition
- ActiveRecord::ConnectionAdapters::PostGISAdapter::TableDefinition
- Defined in:
- lib/active_record/connection_adapters/postgis_adapter/rails4/spatial_table_definition.rb
Overview
:nodoc:
Instance Method Summary collapse
- #column(name_, type_, options_ = {}) ⇒ Object
- #create_column_definition(name_, type_) ⇒ Object
-
#initialize(types_, name_, temporary_, options_, as_, base_) ⇒ TableDefinition
constructor
A new instance of TableDefinition.
- #non_geographic_spatial_columns ⇒ Object
Constructor Details
#initialize(types_, name_, temporary_, options_, as_, base_) ⇒ TableDefinition
Returns a new instance of TableDefinition.
10 11 12 13 14 |
# File 'lib/active_record/connection_adapters/postgis_adapter/rails4/spatial_table_definition.rb', line 10 def initialize(types_, name_, temporary_, , as_, base_) @base = base_ @spatial_columns_hash = {} super(types_, name_, temporary_, , as_) end |
Instance Method Details
#column(name_, type_, options_ = {}) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/active_record/connection_adapters/postgis_adapter/rails4/spatial_table_definition.rb', line 16 def column(name_, type_, ={}) if (info_ = @base.spatial_column_constructor(type_.to_sym)) type_ = [:type] || info_[:type] || type_ if type_.to_s == 'geometry' && ([:no_constraints] || [:limit].is_a?(::Hash) && [:limit][:no_constraints]) then .delete(:limit) else [:type] = type_ type_ = :spatial end end if type_ == :spatial if (limit_ = .delete(:limit)) .merge!(limit_) if limit_.is_a?(::Hash) end if [:geographic] type_ = :geography spatial_type_ = ([:type] || 'geometry').to_s.upcase.gsub('_', '') spatial_type_ << 'Z' if [:has_z] spatial_type_ << 'M' if [:has_m] [:limit] = "#{spatial_type_},#{[:srid] || 4326}" end name_ = name_.to_s if primary_key_column_name == name_ raise ArgumentError, "you can't redefine the primary key column '#{name_}'. To define a custom primary key, pass { id: false } to create_table." end col_ = new_column_definition(name_, type_, ) col_.set_spatial_type([:type]) col_.set_geographic([:geographic]) col_.set_srid([:srid]) col_.set_has_z([:has_z]) col_.set_has_m([:has_m]) (col_.geographic? ? @columns_hash : @spatial_columns_hash)[name_] = col_ else super(name_, type_, ) end self end |
#create_column_definition(name_, type_) ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/active_record/connection_adapters/postgis_adapter/rails4/spatial_table_definition.rb', line 57 def create_column_definition(name_, type_) if type_ == :spatial || type_ == :geography PostGISAdapter::ColumnDefinition.new(name_, type_) else super end end |
#non_geographic_spatial_columns ⇒ Object
65 66 67 |
# File 'lib/active_record/connection_adapters/postgis_adapter/rails4/spatial_table_definition.rb', line 65 def non_geographic_spatial_columns @spatial_columns_hash.values end |