]> git.openstreetmap.org Git - rails.git/blobdiff - app/models/concerns/geo_record.rb
Merge remote-tracking branch 'upstream/pull/4455'
[rails.git] / app / models / concerns / geo_record.rb
index 06049c2951b25876999cc7e3ee0fc070bacd97e6..bd96e0ff33261630e848d65a20926c8b7857a233 100644 (file)
@@ -1,5 +1,3 @@
-require "delegate"
-
 module GeoRecord
   extend ActiveSupport::Concern
 
@@ -7,12 +5,12 @@ module GeoRecord
   # and not e.g. 4.0e-05
   # Unfortunately you can't extend Numeric classes directly (e.g. `Coord < Float`).
   class Coord < DelegateClass(Float)
-    def initialize(obj)
-      super(obj)
+    def to_s
+      format("%<coord>.7f", :coord => self)
     end
 
-    def to_s
-      format("%.7f", self)
+    def as_json(*)
+      format("%<coord>.7f", :coord => self).to_f
     end
   end
 
@@ -22,7 +20,7 @@ module GeoRecord
   SCALE = 10000000
 
   included do
-    scope :bbox, ->(bbox) { where(OSM.sql_for_area(bbox)) }
+    scope :bbox, ->(bbox) { where(OSM.sql_for_area(bbox, "#{table_name}.")) }
     before_save :update_tile
   end