lib/finix/hal_resource.rb in finix-0.16 vs lib/finix/hal_resource.rb in finix-1.0.0
- old
+ new
@@ -3,11 +3,13 @@
attr_accessor :hyperlinks
attr_accessor :attributes
def method_missing(method, *args, &block)
- [@attributes, @attributes['page'] || {}].each do |attrs|
+ attributes = [@attributes]
+ attributes << @attributes['page'] unless @attributes['page'].nil?
+ attributes.each do |attrs|
if attrs.has_key?(method.to_s)
return attrs[method.to_s]
end
end
@@ -26,21 +28,26 @@
end
def load_page_from_response!(response)
body = Finix::Utils.indifferent_read_access response.body
- @hyperlinks = Finix::Utils.eval_class(self, IndifferentHash).new
+ hash_class = Finix::Utils.eval_class(self, IndifferentHash)
+ @hyperlinks = hash_class.new
links = body.delete('_links')
links.each { |key, link| @hyperlinks[key.to_sym] = link[:href] } unless links.nil?
- @attributes = {'items' => [], 'page' => body.delete('page')} # clear attributes
+ page = body.delete('page')
+ @attributes = {'items' => [], 'page' => hash_class.new(page)} # clear attributes
if body.has_key? '_embedded'
resource_name, resources = body.delete('_embedded').first
@resource_class = Finix.from_hypermedia_registry resource_name
@attributes['items'] = resources.map do |attrs|
cls = Finix.from_hypermedia_registry resource_name, attrs
cls.construct_from_response attrs
end
end
+
+ @attributes.merge! body
end
end
end
+