Convert some model mixins to concerns
[rails.git] / app / models / concerns / object_metadata.rb
1 module ObjectMetadata
2   extend ActiveSupport::Concern
3
4   def add_metadata_to_xml_node(el, osm, changeset_cache, user_display_name_cache)
5     el["changeset"] = osm.changeset_id.to_s
6     el["redacted"] = osm.redaction.id.to_s if osm.redacted?
7     el["timestamp"] = osm.timestamp.xmlschema
8     el["version"] = osm.version.to_s
9     el["visible"] = osm.visible.to_s
10
11     if changeset_cache.key?(osm.changeset_id)
12       # use the cache if available
13     else
14       changeset_cache[osm.changeset_id] = osm.changeset.user_id
15     end
16
17     user_id = changeset_cache[osm.changeset_id]
18
19     if user_display_name_cache.key?(user_id)
20       # use the cache if available
21     elsif osm.changeset.user.data_public?
22       user_display_name_cache[user_id] = osm.changeset.user.display_name
23     else
24       user_display_name_cache[user_id] = nil
25     end
26
27     unless user_display_name_cache[user_id].nil?
28       el["user"] = user_display_name_cache[user_id]
29       el["uid"] = user_id.to_s
30     end
31   end
32
33   def add_tags_to_xml_node(el, tags)
34     tags.each do |tag|
35       tag_el = XML::Node.new("tag")
36
37       tag_el["k"] = tag.k
38       tag_el["v"] = tag.v
39
40       el << tag_el
41     end
42   end
43 end