Class: Medie::Json::Driver

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

Overview

Receives Json representations and turn them into hashes. Turn hashes into json objects.

Instance Method Summary collapse

Instance Method Details

#can_handle?(content_type) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/medie/json/driver.rb', line 22

def can_handle?(content_type)
  !(content_type.nil? || content_type.split(";")[0]!="application/json")
end

#marshal(obj, rel) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/medie/json/driver.rb', line 6

def marshal(obj, rel)
  if obj.kind_of? String
    obj
  else
    obj.to_json
  end
end

#unmarshal(content) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/medie/json/driver.rb', line 14

def unmarshal(content)
  if content.nil?
    return {}.extend(Methodize).extend(Linked).use_link_type(Medie::Json::Links)
  end
    
  ::JSON.parse(content).extend(Methodize).extend(Linked).use_link_type(Medie::Json::Links)
end