lib/lazy_resource/relation.rb in lazy_resource-0.3.0 vs lib/lazy_resource/relation.rb in lazy_resource-0.3.2
- old
+ new
@@ -6,11 +6,11 @@
def resource_queue
Thread.current[:resource_queue] ||= ResourceQueue.new
end
end
- attr_accessor :fetched, :klass, :values, :from, :site
+ attr_accessor :fetched, :klass, :values, :from, :site, :other_attributes
def initialize(klass, options = {})
@klass = klass
@values = options.slice(:where_values, :order_value, :limit_value, :offset_value, :page_value)
@fetched = options[:fetched] || false
@@ -20,11 +20,11 @@
self
end
def from
- @from || self.klass.collection_name
+ @from || self.klass.from || self.klass.collection_name
end
def collection_name
from
end
@@ -39,10 +39,23 @@
params
end
def load(objects)
@fetched = true
- @result = @klass.load(objects)
+
+ if @klass.root_node_name && objects.respond_to?(:key?) && objects.key?(@klass.root_node_name.to_s)
+ other_objects = objects.dup
+ objects = other_objects.delete(@klass.root_node_name.to_s)
+ @other_attributes = other_objects
+ end
+
+ @result = objects.map do |object|
+ @klass.load(object)
+ end
+ end
+
+ def headers
+ @headers ||= @klass.default_headers
end
def resource_queue
self.class.resource_queue
end