Class: Mystic::SQL::Column
- Inherits:
-
Object
- Object
- Mystic::SQL::Column
- Defined in:
- lib/mystic/sql/column.rb
Instance Attribute Summary collapse
-
#constraints ⇒ Object
Returns the value of attribute constraints.
-
#geom_kind ⇒ Object
Returns the value of attribute geom_kind.
-
#geom_srid ⇒ Object
Returns the value of attribute geom_srid.
-
#kind ⇒ Object
Returns the value of attribute kind.
-
#name ⇒ Object
Returns the value of attribute name.
-
#size ⇒ Object
Returns the value of attribute size.
Instance Method Summary collapse
- #geospatial? ⇒ Boolean
-
#initialize(opts = {}) ⇒ Column
constructor
A new instance of Column.
- #to_s ⇒ Object
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
#constraints ⇒ Object
Returns the value of attribute constraints.
6 7 8 |
# File 'lib/mystic/sql/column.rb', line 6 def constraints @constraints end |
#geom_kind ⇒ Object
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_srid ⇒ Object
Returns the value of attribute geom_srid.
6 7 8 |
# File 'lib/mystic/sql/column.rb', line 6 def geom_srid @geom_srid end |
#kind ⇒ Object
Returns the value of attribute kind.
6 7 8 |
# File 'lib/mystic/sql/column.rb', line 6 def kind @kind end |
#name ⇒ Object
Returns the value of attribute name.
6 7 8 |
# File 'lib/mystic/sql/column.rb', line 6 def name @name end |
#size ⇒ Object
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
17 18 19 |
# File 'lib/mystic/sql/column.rb', line 17 def geospatial? @geom_kind && @geom_srid end |
#to_s ⇒ Object
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 |