Class: Medie::Xml::Driver

Inherits:
Object
  • Object
show all
Defined in:
lib/medie/xml/driver.rb

Instance Method Summary collapse

Instance Method Details

#can_handle?(content_type) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
30
31
32
# File 'lib/medie/xml/driver.rb', line 27

def can_handle?(content_type)
  !(content_type.nil? ||
    (content_type.split(";")[0]!="application/xml" &&
    content_type.split(";")[0]!="application/atom+xml" &&
    content_type.split(";")[0]!="text/xml"))
end

#marshal(obj, options = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/medie/xml/driver.rb', line 4

def marshal(obj, options = {})
  if(obj.kind_of?(String))
    obj
  elsif obj.kind_of?(Hash) && obj.size==1
    root = obj.values.first
    if !root.respond_to?(:to_xml)
      raise "Trying to marshal a string into xml does not make sense: '#{obj}'"
    end
    root.to_xml(:root => obj.keys.first)
  else
    obj.to_xml
  end
end

#unmarshal(content) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/medie/xml/driver.rb', line 18

def unmarshal(content)
  if content
    hash = Hash.from_xml(content)
  else
    hash = {}
  end
  hash.extend(Methodize).extend(Medie::Linked).use_link_type(Medie::Xml::Links)
end