lib/hyper_resource/adapter/hal_json.rb in hyperresource-0.1.9.5 vs lib/hyper_resource/adapter/hal_json.rb in hyperresource-0.2.0
- old
+ new
@@ -1,10 +1,15 @@
require 'rubygems' if RUBY_VERSION[0..2] == '1.8'
require 'json'
class HyperResource
class Adapter
+
+ ## HyperResource::Adapter::HAL_JSON provides support for the HAL+JSON
+ ## hypermedia format by implementing the interface defined in
+ ## HyperResource::Adapter.
+
class HAL_JSON < Adapter
class << self
def serialize(object)
JSON.dump(object)
@@ -40,28 +45,28 @@
objs = rsrc.objects
resp['_embedded'].each do |name, collection|
if collection.is_a? Hash
r = rc.new(:root => rsrc.root, :namespace => rsrc.namespace)
- r.response_object = collection
+ r.body = collection
objs[name] = apply(collection, r)
else
objs[name] = collection.map do |obj|
r = rc.new(:root => rsrc.root, :namespace => rsrc.namespace)
- r.response_object = obj
+ r.body = obj
apply(obj, r)
end
end
end
- objs.create_methods!
+ objs._hr_create_methods!
end
def apply_links(resp, rsrc)
return unless resp['_links']
- rsrc.links = rsrc._get_response_class::Links.new(rsrc)
+ rsrc.links = rsrc._hr_response_class::Links.new(rsrc)
links = rsrc.links
resp['_links'].each do |rel, link_spec|
if link_spec.is_a? Array
links[rel] = link_spec.map do |link|
@@ -70,28 +75,28 @@
else
links[rel] = new_link_from_spec(rsrc, link_spec)
end
end
- links.create_methods!
+ links._hr_create_methods!
end
- def new_link_from_spec(resource, link_spec) # :nodoc:
+ def new_link_from_spec(resource, link_spec)
resource.class::Link.new(resource, link_spec)
end
def apply_attributes(resp, rsrc)
- rsrc.attributes = rsrc._get_response_class::Attributes.new(rsrc)
+ rsrc.attributes = rsrc._hr_response_class::Attributes.new(rsrc)
given_attrs = resp.reject{|k,v| %w(_links _embedded).include?(k)}
filtered_attrs = rsrc.incoming_body_filter(given_attrs)
filtered_attrs.keys.each do |attr|
rsrc.attributes[attr] = filtered_attrs[attr]
end
- rsrc.attributes.create_methods!
+ rsrc.attributes._hr_create_methods!
end
end
end
end