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
102 results.send('[]', *x)
118 Hash[results.collect { |x| [x.uuid, x] }]
126 results.items_available if results.respond_to? :items_available
130 results.limit if results.respond_to? :limit
134 results.offset if results.respond_to? :offset
138 results.links if results.respond_to? :links
141 def links_for item_or_uuid, link_class=nil
142 unless @links_for_uuid
144 results.links.each do |link|
145 if link.respond_to? :head_uuid
146 @links_for_uuid[link.head_uuid] ||= []
147 @links_for_uuid[link.head_uuid] << link
151 if item_or_uuid.respond_to? :uuid
152 uuid = item_or_uuid.uuid
156 (@links_for_uuid[uuid] || []).select do |link|
157 link.link_class == link_class
161 # Note: this arbitrarily chooses one of (possibly) multiple names.
162 def name_for item_or_uuid
163 links_for(item_or_uuid, 'name').first.andand.name