Class: MySQLPoint::Type
- Inherits:
-
ActiveModel::Type::Value
- Object
- ActiveModel::Type::Value
- MySQLPoint::Type
- Defined in:
- lib/mysql_point/type.rb
Instance Method Summary collapse
-
#cast(value) ⇒ Object
from attribute setter (WKT, Coordinate) to ruby value (Coordinate) and from user input (WKT) to ruby value (Coordinate).
-
#deserialize(value) ⇒ Object
from database value (WKB, Coordinate) to ruby value (Coordinate).
-
#serialize(value) ⇒ Object
from ruby type (Coordinate) to quotable database value (Coordinate) this depends on the MySQLPoint::Quoting mixin to work.
-
#type ⇒ Object
for schema dumping.
Instance Method Details
#cast(value) ⇒ Object
from attribute setter (WKT, Coordinate) to ruby value (Coordinate) and from user input (WKT) to ruby value (Coordinate)
24 25 26 27 28 29 30 |
# File 'lib/mysql_point/type.rb', line 24 def cast(value) if value.respond_to?(:to_wkt) value elsif value MySQLPoint::Coordinate.from_wkt(value) end end |
#deserialize(value) ⇒ Object
from database value (WKB, Coordinate) to ruby value (Coordinate)
14 15 16 17 18 19 20 |
# File 'lib/mysql_point/type.rb', line 14 def deserialize(value) if value.respond_to?(:to_wkt) value elsif value MySQLPoint::Coordinate.from_wkb(value[4..-1]) end end |
#serialize(value) ⇒ Object
from ruby type (Coordinate) to quotable database value (Coordinate) this depends on the MySQLPoint::Quoting mixin to work.
9 10 11 |
# File 'lib/mysql_point/type.rb', line 9 def serialize(value) value end |
#type ⇒ Object
for schema dumping
3 4 5 |
# File 'lib/mysql_point/type.rb', line 3 def type :point end |