Class: Xenon::XmlMarshaller
- Inherits:
-
Object
- Object
- Xenon::XmlMarshaller
show all
- Includes:
- Marshaller
- Defined in:
- lib/xenon/marshallers.rb
Instance Method Summary
collapse
Methods included from Marshaller
#content_type, #marshal?, #unmarshal?
Constructor Details
Returns a new instance of XmlMarshaller.
37
38
39
40
41
42
43
|
# File 'lib/xenon/marshallers.rb', line 37
def initialize
gem 'builder'
require 'active_support/core_ext/array/conversions'
require 'active_support/core_ext/hash/conversions'
rescue Gem::LoadError
raise 'Install the "builder" gem to enable XML.'
end
|
Instance Method Details
#marshal(obj) ⇒ Object
49
50
51
52
|
# File 'lib/xenon/marshallers.rb', line 49
def marshal(obj)
raise "#{obj.class} does not support #to_xml" unless obj.respond_to?(:to_xml)
[obj.to_xml]
end
|
45
46
47
|
# File 'lib/xenon/marshallers.rb', line 45
def media_type
MediaType::XML
end
|
#unmarshal(body, as:) ⇒ Object
54
55
56
|
# File 'lib/xenon/marshallers.rb', line 54
def unmarshal(body, as:)
as.new.from_xml(body.read)
end
|