]> git.openstreetmap.org Git - rails.git/commitdiff
Convert some model mixins to concerns
authorTom Hughes <tom@compton.nu>
Mon, 29 Oct 2018 19:14:55 +0000 (19:14 +0000)
committerTom Hughes <tom@compton.nu>
Mon, 29 Oct 2018 19:14:55 +0000 (19:14 +0000)
app/models/concerns/geo_record.rb [moved from lib/geo_record.rb with 89% similarity]
app/models/concerns/not_redactable.rb [moved from lib/not_redactable.rb with 78% similarity]
app/models/concerns/object_metadata.rb [moved from lib/object_metadata.rb with 97% similarity]

similarity index 89%
rename from lib/geo_record.rb
rename to app/models/concerns/geo_record.rb
index e02734ec909dc8064f78d2cf8e17455287939911..06049c2951b25876999cc7e3ee0fc070bacd97e6 100644 (file)
@@ -1,6 +1,8 @@
 require "delegate"
 
 module GeoRecord
+  extend ActiveSupport::Concern
+
   # Ensure that when coordinates are printed that they are always in decimal degrees,
   # and not e.g. 4.0e-05
   # Unfortunately you can't extend Numeric classes directly (e.g. `Coord < Float`).
@@ -19,9 +21,9 @@ module GeoRecord
   # the database.
   SCALE = 10000000
 
-  def self.included(base)
-    base.scope :bbox, ->(bbox) { base.where(OSM.sql_for_area(bbox)) }
-    base.before_save :update_tile
+  included do
+    scope :bbox, ->(bbox) { where(OSM.sql_for_area(bbox)) }
+    before_save :update_tile
   end
 
   # Is this node within -90 >= latitude >= 90 and -180 >= longitude >= 180
similarity index 78%
rename from lib/not_redactable.rb
rename to app/models/concerns/not_redactable.rb
index 6a57732963989841c89be951c60d941c52e1aed6..2d721530f133fb7f93b3c9c4d58dc4a11469b5de 100644 (file)
@@ -1,6 +1,6 @@
-require "osm"
-
 module NotRedactable
+  extend ActiveSupport::Concern
+
   def redacted?
     false
   end
similarity index 97%
rename from lib/object_metadata.rb
rename to app/models/concerns/object_metadata.rb
index c765df5264d6b749e59e178d847e618e84f40f6e..dcfde889ce83afdbc831185371cc4d7998123b5f 100644 (file)
@@ -1,4 +1,6 @@
 module ObjectMetadata
+  extend ActiveSupport::Concern
+
   def add_metadata_to_xml_node(el, osm, changeset_cache, user_display_name_cache)
     el["changeset"] = osm.changeset_id.to_s
     el["redacted"] = osm.redaction.id.to_s if osm.redacted?