Module: DataMapper::Serializer::ValidationErrors::ToXml

Included in:
Validations::ValidationErrors
Defined in:
lib/dm-serializer/to_xml.rb

Instance Method Summary collapse

Instance Method Details

#to_xml(opts = {}) ⇒ Object



67
68
69
# File 'lib/dm-serializer/to_xml.rb', line 67

def to_xml(opts = {})
  to_xml_document(opts).to_s
end

#to_xml_document(opts = {}) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/dm-serializer/to_xml.rb', line 71

def to_xml_document(opts = {})
  xml = DataMapper::Serializer::XML.serializer
  doc = xml.new_document
  root = xml.root_node(doc, "errors", {'type' => 'hash'})

  errors.each do |key, value|
    property = xml.add_node(root, key.to_s, nil, {'type' => 'array'})
    property.attributes["type"] = 'array'

    value.each do |error|
      xml.add_node(property, "error", error)
    end
  end

  doc
end