lib/zendesk_api/collection.rb in zendesk_api-1.0.0 vs lib/zendesk_api/collection.rb in zendesk_api-1.0.1
- old
+ new
@@ -124,11 +124,11 @@
@resources << item
else
raise "this collection is for #{@resource_class}"
end
else
- @resources << wrap_resource(item)
+ @resources << wrap_resource(item, true)
end
end
# The API path to this collection
def path
@@ -361,17 +361,20 @@
set_page_and_count(body)
set_includes(@resources, @includes, body)
end
# Simplified Associations#wrap_resource
- def wrap_resource(res)
+ def wrap_resource(res, with_association = @resource_class == Tag)
case res
when Array
wrap_resource(Hash[*res])
when Hash
- @resource_class.new(@client, res.merge(:association => association))
+ res = res.merge(:association => @association) if with_association
+ @resource_class.new(@client, res)
else
- @resource_class.new(@client, :id => res, :association => association)
+ res = { :id => res }
+ res.merge!(:association => @association) if with_association
+ @resource_class.new(@client, res)
end
end
## Method missing