Class: DatastaxRails::XmlSerializer
- Inherits:
-
ActiveModel::Serializers::Xml::Serializer
- Object
- ActiveModel::Serializers::Xml::Serializer
- DatastaxRails::XmlSerializer
- Defined in:
- lib/datastax_rails/serializers/xml_serializer.rb
Overview
Implementation of ActiveModel’s XML Serializer
Defined Under Namespace
Classes: Attribute
Instance Method Summary collapse
-
#add_associations(association, records, opts) ⇒ Object
TODO: This can likely be cleaned up to simple use ActiveSupport::XmlMini.to_tag as well.
- #add_extra_behavior ⇒ Object
- #add_includes ⇒ Object
-
#initialize(*args) ⇒ XmlSerializer
constructor
A new instance of XmlSerializer.
Constructor Details
#initialize(*args) ⇒ XmlSerializer
Returns a new instance of XmlSerializer.
185 186 187 |
# File 'lib/datastax_rails/serializers/xml_serializer.rb', line 185 def initialize(*args) super end |
Instance Method Details
#add_associations(association, records, opts) ⇒ Object
TODO: This can likely be cleaned up to simple use ActiveSupport::XmlMini.to_tag as well.
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'lib/datastax_rails/serializers/xml_serializer.rb', line 202 def add_associations(association, records, opts) association_name = association.to_s.singularize = .merge(opts).merge!(root: association_name, skip_instruct: true) if records.is_a?(Enumerable) tag = ActiveSupport::XmlMini.rename_key(association.to_s, ) type = [:skip_types] ? {} : { type: 'array' } if records.empty? @builder.tag!(tag, type) else @builder.tag!(tag, type) do records.each do |record| if [:skip_types] record_type = {} else record_class = (record.class.to_s.underscore == association_name) ? nil : record.class.name record_type = { type: record_class } end record.to_xml .merge(record_type) end end end elsif (record = @serializable.send(association)) record.to_xml() end end |
#add_extra_behavior ⇒ Object
189 190 191 |
# File 'lib/datastax_rails/serializers/xml_serializer.rb', line 189 def add_extra_behavior add_includes end |
#add_includes ⇒ Object
193 194 195 196 197 198 199 |
# File 'lib/datastax_rails/serializers/xml_serializer.rb', line 193 def add_includes procs = .delete(:procs) @serializable.send(:serializable_add_includes, ) do |association, records, opts| add_associations(association, records, opts) end [:procs] = procs end |