X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/abf35dd75665d07bfb3b46f3372b56ba721e6ed7..2168ad210840bf3d0df0b80dfceae92a26e6c970:/app/models/relation.rb diff --git a/app/models/relation.rb b/app/models/relation.rb index a73d63183..5ed838e10 100644 --- a/app/models/relation.rb +++ b/app/models/relation.rb @@ -17,7 +17,7 @@ # current_relations_changeset_id_fkey (changeset_id => changesets.id) # -class Relation < ActiveRecord::Base +class Relation < ApplicationRecord require "xml/libxml" include ConsistencyValidations @@ -54,19 +54,21 @@ class Relation < ActiveRecord::Base TYPES = %w[node way relation].freeze - def self.from_xml(xml, create = false) + def self.from_xml(xml, create: false) p = XML::Parser.string(xml, :options => XML::Parser::Options::NOERROR) doc = p.parse + pt = doc.find_first("//osm/relation") - doc.find("//osm/relation").each do |pt| - return Relation.from_xml_node(pt, create) + if pt + Relation.from_xml_node(pt, :create => create) + else + raise OSM::APIBadXMLError.new("node", xml, "XML doesn't contain an osm/relation element.") end - raise OSM::APIBadXMLError.new("node", xml, "XML doesn't contain an osm/relation element.") rescue LibXML::XML::Error, ArgumentError => e raise OSM::APIBadXMLError.new("relation", xml, e.message) end - def self.from_xml_node(pt, create = false) + def self.from_xml_node(pt, create: false) relation = Relation.new raise OSM::APIBadXMLError.new("relation", pt, "Version is required when updating") unless create || !pt["version"].nil? @@ -132,9 +134,7 @@ class Relation < ActiveRecord::Base @tags ||= Hash[relation_tags.collect { |t| [t.k, t.v] }] end - attr_writer :members - - attr_writer :tags + attr_writer :members, :tags def add_member(type, id, role) @members ||= []