Class: Mystic::SQL::Column

Inherits:
Object
  • Object
show all
Defined in:
lib/mystic/sql/column.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Column

Returns a new instance of Column.



8
9
10
11
12
13
14
15
# File 'lib/mystic/sql/column.rb', line 8

def initialize(opts={})
  @name = opts.delete(:name).to_s
  @kind = opts.delete(:kind).to_sym
  @size = opts.delete(:size).to_s if opts.member? :size
  @geom_kind = opts.delete(:geom_kind)
  @geom_srid = opts.delete(:geom_srid).to_i
  @constraints = opts
end

Instance Attribute Details

#constraintsObject

Returns the value of attribute constraints.



6
7
8
# File 'lib/mystic/sql/column.rb', line 6

def constraints
  @constraints
end

#geom_kindObject

Returns the value of attribute geom_kind.



6
7
8
# File 'lib/mystic/sql/column.rb', line 6

def geom_kind
  @geom_kind
end

#geom_sridObject

Returns the value of attribute geom_srid.



6
7
8
# File 'lib/mystic/sql/column.rb', line 6

def geom_srid
  @geom_srid
end

#kindObject

Returns the value of attribute kind.



6
7
8
# File 'lib/mystic/sql/column.rb', line 6

def kind
  @kind
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/mystic/sql/column.rb', line 6

def name
  @name
end

#sizeObject

Returns the value of attribute size.



6
7
8
# File 'lib/mystic/sql/column.rb', line 6

def size
  @size
end

Instance Method Details

#geospatial?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/mystic/sql/column.rb', line 17

def geospatial?
				@geom_kind && @geom_srid
end

#to_sObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/mystic/sql/column.rb', line 21

def to_s
  			sql = []
  			sql << name
  			sql << kind.downcase
  			sql << "(#{size})" if size && !size.empty? && !geospatial?
  			sql << "(#{geom_kind}, #{geom_srid})" if geospatial?
  sql << (constraints[:null] ? "NULL" : "NOT NULL") if constraints.member?(:null)
  			sql << "UNIQUE" if constraints[:unique]
  			sql << "PRIMARY KEY" if constraints[:primary_key]
  			sql << "REFERENCES " + constraints[:references] if constraints.member?(:references)
  			sql << "DEFAULT " + constraints[:default] if constraints.member?(:default)
  			sql << "CHECK(#{constraints[:check]})" if constraints.member?(:check)
  			sql*" "
end