class DataMapper::Validate::ValidationErrors

By default DataMapper validation errors doesn’t have to_xml method. This is actually very useful when dealing with remote stateful clients such as Flex/AIR.

Public Instance Methods

to_json() click to toggle source

Add #to_json support for datamapper errors too

# File lib/restfulx/rx_datamapper.rb, line 74
def to_json
  @errors.to_json
end
to_xml() click to toggle source

Add Flex-friendly to_xml implementation

# File lib/restfulx/rx_datamapper.rb, line 56
def to_xml
  xml = DataMapper::Serialize::XMLSerializers::SERIALIZER
  doc ||= xml.new_document
  root = xml.root_node(doc, "errors")
  @errors.each_key do |attribute|
    @errors[attribute].each do |msg|
      next if msg.nil?
      if attribute == "base"
        xml.add_node(root, "error", nil, {"message" => msg})
      else
        xml.add_node(root, "error", nil, {"field" => attribute.to_s.camel_case.dcfirst, "message" => msg})
      end
    end
  end
  xml.output(doc)
end