Froze rails gems
[depot.git] / vendor / rails / activeresource / lib / active_resource / formats / xml_format.rb
1 module ActiveResource
2 module Formats
3 module XmlFormat
4 extend self
5
6 def extension
7 "xml"
8 end
9
10 def mime_type
11 "application/xml"
12 end
13
14 def encode(hash, options={})
15 hash.to_xml(options)
16 end
17
18 def decode(xml)
19 from_xml_data(Hash.from_xml(xml))
20 end
21
22 private
23 # Manipulate from_xml Hash, because xml_simple is not exactly what we
24 # want for Active Resource.
25 def from_xml_data(data)
26 if data.is_a?(Hash) && data.keys.size == 1
27 data.values.first
28 else
29 data
30 end
31 end
32 end
33 end
34 end