Class: Backframe::Response::Adapter::Xml

Inherits:
Object
  • Object
show all
Defined in:
lib/backframe/response/adapter/xml.rb

Class Method Summary collapse

Class Method Details

.render(collection, fields) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/backframe/response/adapter/xml.rb', line 13

def render(collection, fields)
  output  = '<?xml version="1.0"?>'
  output += "<records>"
  collection.records.each do |item|
    serialized = ActiveModelSerializers::SerializableResource.new(item).serializable_hash
    output += "<record>"
    fields.array.each do |field|
      value = Backframe::Response::Record.get_value(serialized, field[:key])
      output += "<#{field[:key]}>#{value}</#{field[:key]}>"
    end
    output += "</record>"
  end
  output += "</records>"
  output
end