Class: Delineate::Serializers::XmlSerializer
- Inherits:
-
MapSerializer
- Object
- MapSerializer
- Delineate::Serializers::XmlSerializer
- Defined in:
- lib/delineate/serializers/xml_serializer.rb
Overview
AttributeMap serializer that handles XML as the external data format.
Instance Method Summary collapse
-
#serialize(options = {}) ⇒ Object
Returns the record’s mapped attributes as XML.
-
#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.
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( = {}) hash = super() if [:root] == true root_option = {:root => @record.class.model_name.element} elsif [:root] root_option = {:root => [:root]} else root_option = {} end opts = ().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, = {}) super(Hash.from_xml(xml_string), ) end |