Changeset 6519
- Timestamp:
- 04/13/07 01:26:17 (2 years ago)
- Files:
-
- trunk/activerecord/CHANGELOG (modified) (1 diff)
- trunk/activerecord/lib/active_record/xml_serialization.rb (modified) (3 diffs)
- trunk/activerecord/test/xml_serialization_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activerecord/CHANGELOG
r6470 r6519 1 1 *SVN* 2 3 * Added yielding of Builder instance for ActiveRecord::Base#to_xml calls [DHH] 2 4 3 5 * Small additions and fixes for ActiveRecord documentation. Closes #7342 [jeremymcanally] trunk/activerecord/lib/active_record/xml_serialization.rb
r6444 r6519 91 91 # </firm> 92 92 # 93 # Alternatively, you can also just yield the builder object as part of the to_xml call: 94 # 95 # firm.to_xml do |xml| 96 # xml.creator do 97 # xml.first_name "David" 98 # xml.last_name "Heinemeier Hansson" 99 # end 100 # end 101 # 102 # <firm> 103 # # ... normal attributes as shown above ... 104 # <creator> 105 # <first_name>David</first_name> 106 # <last_name>Heinemeier Hansson</last_name> 107 # </creator> 108 # </firm> 109 # 93 110 # You may override the to_xml method in your ActiveRecord::Base 94 111 # subclasses if you need to. The general form of doing this is … … 104 121 # end 105 122 # end 106 def to_xml(options = {}) 107 XmlSerializer.new(self, options).to_s 123 def to_xml(options = {}, &block) 124 serializer = XmlSerializer.new(self, options) 125 block_given? ? serializer.to_s(&block) : serializer.to_s 108 126 end 109 127 end … … 232 250 add_includes 233 251 add_procs 252 yield builder if block_given? 234 253 end 235 254 end trunk/activerecord/test/xml_serialization_test.rb
r6444 r6519 56 56 assert_no_match %r{<age}, @xml 57 57 assert_match %r{<created-at}, @xml 58 end 59 60 def test_should_include_yielded_additions 61 @xml = Contact.new.to_xml do |xml| 62 xml.creator "David" 63 end 64 65 assert_match %r{<creator>David</creator>}, @xml 58 66 end 59 67 end