Class: ActiveRecord::ConnectionAdapters::PostgreSQLColumnDefinition
- Inherits:
-
ColumnDefinition
- Object
- ColumnDefinition
- ActiveRecord::ConnectionAdapters::PostgreSQLColumnDefinition
- Defined in:
- lib/postgis_adapter/init.rb
Instance Attribute Summary collapse
-
#spatial ⇒ Object
readonly
Returns the value of attribute spatial.
-
#srid ⇒ Object
Returns the value of attribute srid.
-
#with_m ⇒ Object
Returns the value of attribute with_m.
-
#with_z ⇒ Object
Returns the value of attribute with_z.
Instance Method Summary collapse
-
#initialize(base = nil, name = nil, type = nil, limit = nil, default = nil, null = nil, srid = -1,, with_z = false, with_m = false) ⇒ PostgreSQLColumnDefinition
constructor
A new instance of PostgreSQLColumnDefinition.
- #to_sql(table_name) ⇒ Object
Constructor Details
#initialize(base = nil, name = nil, type = nil, limit = nil, default = nil, null = nil, srid = -1,, with_z = false, with_m = false) ⇒ PostgreSQLColumnDefinition
Returns a new instance of PostgreSQLColumnDefinition.
398 399 400 401 402 403 404 |
# File 'lib/postgis_adapter/init.rb', line 398 def initialize(base = nil, name = nil, type=nil, limit=nil, default=nil,null=nil,srid=-1,with_z=false,with_m=false) super(base, name, type, limit, default,null) @spatial=true @srid=srid @with_z=with_z @with_m=with_m end |
Instance Attribute Details
#spatial ⇒ Object (readonly)
Returns the value of attribute spatial.
396 397 398 |
# File 'lib/postgis_adapter/init.rb', line 396 def spatial @spatial end |
#srid ⇒ Object
Returns the value of attribute srid.
395 396 397 |
# File 'lib/postgis_adapter/init.rb', line 395 def srid @srid end |
#with_m ⇒ Object
Returns the value of attribute with_m.
395 396 397 |
# File 'lib/postgis_adapter/init.rb', line 395 def with_m @with_m end |
#with_z ⇒ Object
Returns the value of attribute with_z.
395 396 397 |
# File 'lib/postgis_adapter/init.rb', line 395 def with_z @with_z end |
Instance Method Details
#to_sql(table_name) ⇒ Object
406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 |
# File 'lib/postgis_adapter/init.rb', line 406 def to_sql(table_name) if @spatial type_sql = type_to_sql(type.to_sym) type_sql += "M" if with_m and !with_z if with_m and with_z dimension = 4 elsif with_m or with_z dimension = 3 else dimension = 2 end column_sql = "SELECT AddGeometryColumn('#{table_name}','#{name}',#{srid},'#{type_sql}',#{dimension})" column_sql += ";ALTER TABLE #{table_name} ALTER #{name} SET NOT NULL" if null == false column_sql else super end end |