1 class ArvadosResourceList
4 def initialize resource_class=nil
5 @resource_class = resource_class
13 def limit(max_results)
23 def order(orderby_spec)
24 @orderby_spec = orderby_spec
36 cond.keys.each do |uuid_key|
37 if cond[uuid_key] and (cond[uuid_key].is_a? Array or
38 cond[uuid_key].is_a? ArvadosBase)
39 # Coerce cond[uuid_key] to an array of uuid strings. This
40 # allows caller the convenience of passing an array of real
41 # objects and uuids in cond[uuid_key].
42 if !cond[uuid_key].is_a? Array
43 cond[uuid_key] = [cond[uuid_key]]
45 cond[uuid_key] = cond[uuid_key].collect do |item|
46 if item.is_a? ArvadosBase
54 cond.keys.select { |x| x.match /_kind$/ }.each do |kind_key|
55 if cond[kind_key].is_a? Class
56 cond = cond.merge({ kind_key => 'arvados#' + $arvados_api_client.class_kind(cond[kind_key]) })
63 api_params[:eager] = '1' if @eager
64 api_params[:limit] = @limit if @limit
65 api_params[:offset] = @offset if @offset
66 api_params[:order] = @orderby_spec if @orderby_spec
67 api_params[:filters] = @filters if @filters
68 res = $arvados_api_client.api @resource_class, '', api_params
69 @results = $arvados_api_client.unpack_api_response res
74 self.where({}) if !@results
94 results.collect do |m|
108 results.send('[]', *x)
124 Hash[results.collect { |x| [x.uuid, x] }]
132 results.items_available if results.respond_to? :items_available
136 results.limit if results.respond_to? :limit
140 results.offset if results.respond_to? :offset
144 results.links if results.respond_to? :links
147 # Return links provided with API response that point to the
148 # specified object, and have the specified link_class. If link_class
149 # is false or omitted, return all links pointing to the specified
151 def links_for item_or_uuid, link_class=false
152 return [] if !result_links
153 unless @links_for_uuid
155 result_links.each do |link|
156 if link.respond_to? :head_uuid
157 @links_for_uuid[link.head_uuid] ||= []
158 @links_for_uuid[link.head_uuid] << link
162 if item_or_uuid.respond_to? :uuid
163 uuid = item_or_uuid.uuid
167 (@links_for_uuid[uuid] || []).select do |link|
168 link_class == false or link.link_class == link_class
172 # Note: this arbitrarily chooses one of (possibly) multiple names.
173 def name_for item_or_uuid
174 links_for(item_or_uuid, 'name').first.andand.name