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
43 cond.keys.each do |uuid_key|
44 if cond[uuid_key] and (cond[uuid_key].is_a? Array or
45 cond[uuid_key].is_a? ArvadosBase)
46 # Coerce cond[uuid_key] to an array of uuid strings. This
47 # allows caller the convenience of passing an array of real
48 # objects and uuids in cond[uuid_key].
49 if !cond[uuid_key].is_a? Array
50 cond[uuid_key] = [cond[uuid_key]]
52 cond[uuid_key] = cond[uuid_key].collect do |item|
53 if item.is_a? ArvadosBase
61 cond.keys.select { |x| x.match /_kind$/ }.each do |kind_key|
62 if cond[kind_key].is_a? Class
63 cond = cond.merge({ kind_key => 'arvados#' + arvados_api_client.class_kind(cond[kind_key]) })
70 api_params[:eager] = '1' if @eager
71 api_params[:limit] = @limit if @limit
72 api_params[:offset] = @offset if @offset
73 api_params[:select] = @select if @select
74 api_params[:order] = @orderby_spec if @orderby_spec
75 api_params[:filters] = @filters if @filters
76 res = arvados_api_client.api @resource_class, '', api_params
77 @results = arvados_api_client.unpack_api_response res
82 self.where({}) if !@results
102 results.collect do |m|
116 results.send('[]', *x)
132 Hash[results.collect { |x| [x.uuid, x] }]
140 results.items_available if results.respond_to? :items_available
144 results.limit if results.respond_to? :limit
148 results.offset if results.respond_to? :offset
152 results.links if results.respond_to? :links
155 # Return links provided with API response that point to the
156 # specified object, and have the specified link_class. If link_class
157 # is false or omitted, return all links pointing to the specified
159 def links_for item_or_uuid, link_class=false
160 return [] if !result_links
161 unless @links_for_uuid
163 result_links.each do |link|
164 if link.respond_to? :head_uuid
165 @links_for_uuid[link.head_uuid] ||= []
166 @links_for_uuid[link.head_uuid] << link
170 if item_or_uuid.respond_to? :uuid
171 uuid = item_or_uuid.uuid
175 (@links_for_uuid[uuid] || []).select do |link|
176 link_class == false or link.link_class == link_class
180 # Note: this arbitrarily chooses one of (possibly) multiple names.
181 def name_for item_or_uuid
182 links_for(item_or_uuid, 'name').first.andand.name