lib/mongoid_geospatial/fields/point.rb in mongoid_geospatial-1.0.0 vs lib/mongoid_geospatial/fields/point.rb in mongoid_geospatial-2.0.0

- old
+ new

@@ -1,21 +1,34 @@ module Mongoid module Geospatial class Point - def mongoize(object) - return unless object && !object.empty? - RGeo::Geographic.spherical_factory.point *object - #["x"], object["y"] + def mongoize + [x, y] end - def demongoize(object) - object.respond_to?(:x) ? [object.x, object.y] : object - # if object.respond_to? :x - # { "x" => object.x, "y" => object.y } - # else - # { "x" => object[0], "y" => object[1] } - # end + class << self + + def demongoize(object) + return unless object && !object.empty? + RGeo::Geographic.spherical_factory.point *object + #["x"], object["y"] + end + + def mongoize(object) + #return new.mongoize if object.respond_to?(:x) + case object + when Point then object.mongoize + when Hash then [object[:x], object[:y]] + else object + end + end + + # Converts the object that was supplied to a criteria and converts it + # into a database friendly form. + def evolve(object) + object.respond_to?(:x) ? object.mongoize : object + end end # - self.spacial_fields ||= [] # - self.spacial_fields << field.name.to_sym if self.spacial_fields.kind_of? Array # -