X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/3426976606d30278fcf5ed279d3c95900785c4a5..8e02c98c3fb052803c4a70a35b14c1d1ca9c4119:/app/models/relation.rb diff --git a/app/models/relation.rb b/app/models/relation.rb index 3f812d1b1..5ed838e10 100644 --- a/app/models/relation.rb +++ b/app/models/relation.rb @@ -54,19 +54,21 @@ class Relation < ApplicationRecord 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 < ApplicationRecord @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 ||= []