From: Shaun McDonald Date: Mon, 13 Oct 2008 14:34:04 +0000 (+0000) Subject: moving the check consistency to it's own file so that checks will be able to be loade... X-Git-Tag: live~7601^2~278 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/b91b514cf22f04910c83b6dcc254908ed37d7413 moving the check consistency to it's own file so that checks will be able to be loaded into the way and relation models, without loading the node stuff. --- diff --git a/app/models/node.rb b/app/models/node.rb index 39e1228ac..e7058a5ad 100644 --- a/app/models/node.rb +++ b/app/models/node.rb @@ -2,6 +2,7 @@ class Node < ActiveRecord::Base require 'xml/libxml' include GeoRecord + include ConsistencyValidations set_table_name 'current_nodes' diff --git a/app/models/old_node.rb b/app/models/old_node.rb index e7d803044..8b3ba784b 100644 --- a/app/models/old_node.rb +++ b/app/models/old_node.rb @@ -1,5 +1,6 @@ class OldNode < ActiveRecord::Base include GeoRecord + include ConsistencyValidations set_table_name 'nodes' diff --git a/app/models/old_relation.rb b/app/models/old_relation.rb index 10c76a758..3a7cc29b2 100644 --- a/app/models/old_relation.rb +++ b/app/models/old_relation.rb @@ -1,4 +1,6 @@ class OldRelation < ActiveRecord::Base + include ConsistencyValidations + set_table_name 'relations' belongs_to :changeset diff --git a/app/models/old_way.rb b/app/models/old_way.rb index f297cfc1a..13c935fe6 100644 --- a/app/models/old_way.rb +++ b/app/models/old_way.rb @@ -1,4 +1,6 @@ class OldWay < ActiveRecord::Base + include ConsistencyValidations + set_table_name 'ways' belongs_to :changeset diff --git a/app/models/relation.rb b/app/models/relation.rb index c8ee89d37..081c44b25 100644 --- a/app/models/relation.rb +++ b/app/models/relation.rb @@ -1,6 +1,8 @@ class Relation < ActiveRecord::Base require 'xml/libxml' + include ConsistencyValidations + set_table_name 'current_relations' belongs_to :changeset diff --git a/app/models/way.rb b/app/models/way.rb index 05b412b29..6a5ad58ab 100644 --- a/app/models/way.rb +++ b/app/models/way.rb @@ -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 index 000000000..4becce89c --- /dev/null +++ b/lib/consistency_validations.rb @@ -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 diff --git a/lib/geo_record.rb b/lib/geo_record.rb index 645ddc93a..2740eab0c 100644 --- a/lib/geo_record.rb +++ b/lib/geo_record.rb @@ -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)