Skip to content

Commit

Permalink
marshalling json
Browse files Browse the repository at this point in the history
  • Loading branch information
guilhermesilveira committed Dec 27, 2010
1 parent 11ee745 commit f1f41a0
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Gemfile
Expand Up @@ -12,4 +12,5 @@ group :development do
gem "rcov", ">= 0"
end

gem "methodize"
gem "methodize"
gem "json_pure"
2 changes: 2 additions & 0 deletions Gemfile.lock
Expand Up @@ -7,6 +7,7 @@ GEM
bundler (~> 1.0.0)
git (>= 1.2.5)
rake
json_pure (1.4.6)
methodize (0.1)
rake (0.8.7)
rcov (0.9.9)
Expand All @@ -25,6 +26,7 @@ PLATFORMS
DEPENDENCIES
bundler (~> 1.0.0)
jeweler (~> 1.5.2)
json_pure
methodize
rcov
rspec (~> 2.3.0)
9 changes: 7 additions & 2 deletions lib/medie/json.rb
@@ -1,6 +1,7 @@
require 'methodize'
require 'medie/json/linked_json'
require 'medie/json/link_collection'
require 'json'

module Medie

Expand All @@ -16,8 +17,12 @@ def unmarshal(content)
::JSON.parse(content).extend(Methodize).extend(LinkedJson)
end

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

def can_handle?(content_type)
Expand Down
8 changes: 8 additions & 0 deletions spec/medie/json_spec.rb
Expand Up @@ -28,6 +28,14 @@
result.should be_kind_of(Medie::LinkedJson)
end

it "should return the unmarshalled json hash enhanced" do
result = Medie::Json.new.unmarshal({"name" => "guilherme"}.to_json)
result.should == {"name" => "guilherme"}
result.should be_kind_of(Hash)
result.should be_kind_of(Methodize)
result.should be_kind_of(Medie::LinkedJson)
end

end

end

0 comments on commit f1f41a0

Please sign in to comment.