Class: ActiveRecord::XmlSerializer
- Inherits:
-
ActiveModel::Serializers::Xml::Serializer
- Object
- ActiveModel::Serializers::Xml::Serializer
- ActiveRecord::XmlSerializer
- Defined in:
- activerecord/lib/active_record/serializers/xml_serializer.rb
Overview
:nodoc:
Defined Under Namespace
Classes: Attribute
Instance Attribute Summary
Attributes inherited from ActiveModel::Serializers::Xml::Serializer
Instance Method Summary (collapse)
-
- (Object) add_associations(association, records, opts)
TODO This can likely be cleaned up to simple use ActiveSupport::XmlMini.to_tag as well.
- - (Object) add_extra_behavior
- - (Object) add_includes
-
- (XmlSerializer) initialize(*args)
constructor
A new instance of XmlSerializer.
Methods inherited from ActiveModel::Serializers::Xml::Serializer
#attributes_hash, #serializable_attributes, #serializable_methods, #serialize
Constructor Details
- (XmlSerializer) initialize(*args)
A new instance of XmlSerializer
180 181 182 183 |
# File 'activerecord/lib/active_record/serializers/xml_serializer.rb', line 180 def initialize(*args) super [:except] |= Array.wrap(@serializable.class.inheritance_column) end |
Instance Method Details
- (Object) add_associations(association, records, opts)
TODO This can likely be cleaned up to simple use ActiveSupport::XmlMini.to_tag as well.
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
# File 'activerecord/lib/active_record/serializers/xml_serializer.rb', line 198 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 |
- (Object) add_extra_behavior
185 186 187 |
# File 'activerecord/lib/active_record/serializers/xml_serializer.rb', line 185 def add_extra_behavior add_includes end |
- (Object) add_includes
189 190 191 192 193 194 195 |
# File 'activerecord/lib/active_record/serializers/xml_serializer.rb', line 189 def add_includes procs = .delete(:procs) @serializable.send(:serializable_add_includes, ) do |association, records, opts| add_associations(association, records, opts) end [:procs] = procs end |