Class: Delineate::Serializers::XmlSerializer

Inherits:
MapSerializer show all
Defined in:
lib/delineate/serializers/xml_serializer.rb

Overview

AttributeMap serializer that handles XML as the external data format.

Instance Method Summary collapse

Methods inherited from MapSerializer

#initialize, #serializable_record

Constructor Details

This class inherits a constructor from Delineate::MapSerializer

Instance Method Details

#serialize(options = {}) ⇒ Object

Returns the record’s mapped attributes as XML. The specified options are passed to the XML builder. Some typical options are:

:root
:dasherize
:skip_types
:skip_instruct
:indent


16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/delineate/serializers/xml_serializer.rb', line 16

def serialize(options = {})
  hash = super()

  if options[:root] == true
    root_option = {:root => @record.class.model_name.element}
  elsif options[:root]
    root_option = {:root => options[:root]}
  else
    root_option = {}
  end
  opts = remove_serializer_class_options(options).merge(root_option)

  hash.to_xml(opts)
end

#serialize_in(xml_string, options = {}) ⇒ Object

Takes a record’s attributes represented in XML, and returns a hash suitable for direct assignment to the record’s collection of attributes. For example:

s = Delineate::AttributeMap::XmlSerializer.new(record, :api)
record.attributes = s.serialize_in(xml_string)


38
39
40
# File 'lib/delineate/serializers/xml_serializer.rb', line 38

def serialize_in(xml_string, options = {})
  super(Hash.from_xml(xml_string), options)
end