]> git.openstreetmap.org Git - rails.git/commitdiff
moving the check consistency to it's own file so that checks will be able to be loade...
authorShaun McDonald <shaun@shaunmcdonald.me.uk>
Mon, 13 Oct 2008 14:34:04 +0000 (14:34 +0000)
committerShaun McDonald <shaun@shaunmcdonald.me.uk>
Mon, 13 Oct 2008 14:34:04 +0000 (14:34 +0000)
app/models/node.rb
app/models/old_node.rb
app/models/old_relation.rb
app/models/old_way.rb
app/models/relation.rb
app/models/way.rb
lib/consistency_validations.rb [new file with mode: 0644]
lib/geo_record.rb

index 39e1228acf80c8dd41f6d2c4be520c80be736637..e7058a5adee06268b22ff9ffd562d25cc9138c56 100644 (file)
@@ -2,6 +2,7 @@ class Node < ActiveRecord::Base
   require 'xml/libxml'
 
   include GeoRecord
+  include ConsistencyValidations
 
   set_table_name 'current_nodes'
 
index e7d803044a4bd39ac658681e27ce70bda3156466..8b3ba784bfb834c7598b932f5e31212f14bd24ad 100644 (file)
@@ -1,5 +1,6 @@
 class OldNode < ActiveRecord::Base
   include GeoRecord
+  include ConsistencyValidations
 
   set_table_name 'nodes'
   
index 10c76a758cc4561dfbf2babb89bc0f9f4358dd21..3a7cc29b2b95b80cb12c9662876f636d6d63e895 100644 (file)
@@ -1,4 +1,6 @@
 class OldRelation < ActiveRecord::Base
+  include ConsistencyValidations
+  
   set_table_name 'relations'
 
   belongs_to :changeset
index f297cfc1ac01ac3800436817dd59c614a011aaf5..13c935fe6dd2cab8cd1e46492cdd67acafeb2ca9 100644 (file)
@@ -1,4 +1,6 @@
 class OldWay < ActiveRecord::Base
+  include ConsistencyValidations
+  
   set_table_name 'ways'
 
   belongs_to :changeset
index c8ee89d374aa63a69a282dd1d2806c0ea1ee1090..081c44b25d13cc45e1fc0172bfda0411558bc90e 100644 (file)
@@ -1,6 +1,8 @@
 class Relation < ActiveRecord::Base
   require 'xml/libxml'
   
+  include ConsistencyValidations
+  
   set_table_name 'current_relations'
 
   belongs_to :changeset
index 05b412b299f888bfab09026bed4b89d0414c3cb4..6a5ad58ab9635d36279acba547bbe1618815a9ed 100644 (file)
@@ -1,5 +1,7 @@
 class Way < ActiveRecord::Base
   require 'xml/libxml'
+  
+  include ConsistencyValidations
 
   set_table_name 'current_ways'
 
diff --git a/lib/consistency_validations.rb b/lib/consistency_validations.rb
new file mode 100644 (file)
index 0000000..4becce8
--- /dev/null
@@ -0,0 +1,19 @@
+module ConsistencyValidations
+  # Generic checks that are run for the updates and deletes of
+  # node, ways and relations. This code is here to avoid duplication, 
+  # and allow the extention of the checks without having to modify the
+  # code in 6 places for all the updates and deletes. Some of these tests are 
+  # needed for creates, but are currently not run :-( 
+  # This will throw an exception if there is an inconsistency
+  def check_consistency(old, new, user)
+    if new.version != old.version
+      raise OSM::APIVersionMismatchError.new(new.version, old.version)
+    elsif new.changeset.nil?
+      raise OSM::APIChangesetMissingError.new
+    elsif new.changeset.user_id != user.id
+      raise OSM::APIUserChangesetMismatchError.new
+    elsif not new.changeset.is_open?
+      raise OSM::APIChangesetAlreadyClosedError.new
+    end
+  end
+end
index 645ddc93a7f509549a98b9f61eceb83b5e87845a..2740eab0c5472da4c76d95128c5f8253dd440cbb 100644 (file)
@@ -42,23 +42,6 @@ module GeoRecord
     return self.longitude.to_f / SCALE
   end
 
-  # Generic checks that are run for the updates and deletes of
-  # node, ways and relations. This code is here to avoid duplication, 
-  # and allow the extention of the checks without having to modify the
-  # code in 6 places for all the updates and deletes. Some of these tests are 
-  # needed for creates, but are currently not run :-( 
-  # This will throw an exception if there is an inconsistency
-  def check_consistency(old, new, user)
-    if new.version != old.version
-      raise OSM::APIVersionMismatchError.new(new.version, old.version)
-    elsif new.changeset.nil?
-      raise OSM::APIChangesetMissingError.new
-    elsif new.changeset.user_id != user.id
-      raise OSM::APIUserChangesetMismatchError.new
-    elsif not new.changeset.is_open?
-      raise OSM::APIChangesetAlreadyClosedError.new
-    end
-  end
 private
   
   def lat2y(a)