Class: ActiveRecord::XmlSerializer
- Inherits:
-
ActiveModel::Serializers::Xml::Serializer
- Object
- ActiveModel::Serializers::Xml::Serializer
- ActiveRecord::XmlSerializer
- Defined in:
- lib/active_record/serializers/xml_serializer.rb
Overview
:nodoc:
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.
180 181 182 183 |
# File 'lib/active_record/serializers/xml_serializer.rb', line 180 def initialize(*args) super [:except] |= Array.wrap(@serializable.class.inheritance_column) 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.
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 '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 |
#add_extra_behavior ⇒ Object
185 186 187 |
# File 'lib/active_record/serializers/xml_serializer.rb', line 185 def add_extra_behavior add_includes end |
#add_includes ⇒ Object
189 190 191 192 193 194 195 |
# File '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 |