diff options
author | Emilio Tagua <miloops@gmail.com> | 2009-08-14 12:34:38 -0300 |
---|---|---|
committer | Emilio Tagua <miloops@gmail.com> | 2009-08-14 12:34:38 -0300 |
commit | 48c1e6d584409d774b184e0f4d2ef28e5b0e9c90 (patch) | |
tree | a2becf0cce37a47579e848780b02f420d335ccd9 /activerecord/lib/active_record/serializers/xml_serializer.rb | |
parent | 9ac01fad193b27e517ea772e0d1e13e06f4ddf34 (diff) | |
parent | c6bc8e662614be711f45a8d4b231d5f993b024a7 (diff) | |
download | rails-48c1e6d584409d774b184e0f4d2ef28e5b0e9c90.tar.gz rails-48c1e6d584409d774b184e0f4d2ef28e5b0e9c90.tar.bz2 rails-48c1e6d584409d774b184e0f4d2ef28e5b0e9c90.zip |
Merge commit 'rails/master'
Diffstat (limited to 'activerecord/lib/active_record/serializers/xml_serializer.rb')
-rw-r--r-- | activerecord/lib/active_record/serializers/xml_serializer.rb | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/activerecord/lib/active_record/serializers/xml_serializer.rb b/activerecord/lib/active_record/serializers/xml_serializer.rb index 4e172bd2b6..b19920741e 100644 --- a/activerecord/lib/active_record/serializers/xml_serializer.rb +++ b/activerecord/lib/active_record/serializers/xml_serializer.rb @@ -2,6 +2,8 @@ require 'active_support/core_ext/hash/conversions' module ActiveRecord #:nodoc: module Serialization + include ActiveModel::Serializers::Xml + # Builds an XML document to represent the model. Some configuration is # available through +options+. However more complicated cases should # override ActiveRecord::Base#to_xml. @@ -169,18 +171,15 @@ module ActiveRecord #:nodoc: # end # end def to_xml(options = {}, &block) - serializer = XmlSerializer.new(self, options) - block_given? ? serializer.to_s(&block) : serializer.to_s - end - - def from_xml(xml) - self.attributes = Hash.from_xml(xml).values.first - self + XmlSerializer.new(self, options).serialize(&block) end end class XmlSerializer < ActiveModel::Serializers::Xml::Serializer #:nodoc: - include Serialization::RecordSerializer + def initialize(*args) + super + options[:except] |= Array.wrap(@serializable.class.inheritance_column) + end def serializable_attributes serializable_attribute_names.collect { |name| Attribute.new(name, @serializable) } @@ -235,7 +234,9 @@ module ActiveRecord #:nodoc: builder.tag!(*args) do add_attributes procs = options.delete(:procs) - add_includes { |association, records, opts| add_associations(association, records, opts) } + @serializable.send(:serializable_add_includes, options) { |association, records, opts| + add_associations(association, records, opts) + } options[:procs] = procs add_procs yield builder if block_given? |