1 class ArvadosResourceList
2 include ArvadosApiClientHelper
5 def initialize resource_class=nil
6 @resource_class = resource_class
14 def limit(max_results)
24 def order(orderby_spec)
25 @orderby_spec = orderby_spec
37 cond.keys.each do |uuid_key|
38 if cond[uuid_key] and (cond[uuid_key].is_a? Array or
39 cond[uuid_key].is_a? ArvadosBase)
40 # Coerce cond[uuid_key] to an array of uuid strings. This
41 # allows caller the convenience of passing an array of real
42 # objects and uuids in cond[uuid_key].
43 if !cond[uuid_key].is_a? Array
44 cond[uuid_key] = [cond[uuid_key]]
46 cond[uuid_key] = cond[uuid_key].collect do |item|
47 if item.is_a? ArvadosBase
55 cond.keys.select { |x| x.match /_kind$/ }.each do |kind_key|
56 if cond[kind_key].is_a? Class
57 cond = cond.merge({ kind_key => 'arvados#' + arvados_api_client.class_kind(cond[kind_key]) })
64 api_params[:eager] = '1' if @eager
65 api_params[:limit] = @limit if @limit
66 api_params[:offset] = @offset if @offset
67 api_params[:order] = @orderby_spec if @orderby_spec
68 api_params[:filters] = @filters if @filters
69 res = arvados_api_client.api @resource_class, '', api_params
70 @results = arvados_api_client.unpack_api_response res
75 self.where({}) if !@results
95 results.collect do |m|
109 results.send('[]', *x)
125 Hash[results.collect { |x| [x.uuid, x] }]
133 results.items_available if results.respond_to? :items_available
137 results.limit if results.respond_to? :limit
141 results.offset if results.respond_to? :offset
145 results.links if results.respond_to? :links
148 # Return links provided with API response that point to the
149 # specified object, and have the specified link_class. If link_class
150 # is false or omitted, return all links pointing to the specified
152 def links_for item_or_uuid, link_class=false
153 return [] if !result_links
154 unless @links_for_uuid
156 result_links.each do |link|
157 if link.respond_to? :head_uuid
158 @links_for_uuid[link.head_uuid] ||= []
159 @links_for_uuid[link.head_uuid] << link
163 if item_or_uuid.respond_to? :uuid
164 uuid = item_or_uuid.uuid
168 (@links_for_uuid[uuid] || []).select do |link|
169 link_class == false or link.link_class == link_class
173 # Note: this arbitrarily chooses one of (possibly) multiple names.
174 def name_for item_or_uuid
175 links_for(item_or_uuid, 'name').first.andand.name