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
29 def select(columns=nil)
30 # If no column arguments were given, invoke Enumerable#select.
48 cond.keys.each do |uuid_key|
49 if cond[uuid_key] and (cond[uuid_key].is_a? Array or
50 cond[uuid_key].is_a? ArvadosBase)
51 # Coerce cond[uuid_key] to an array of uuid strings. This
52 # allows caller the convenience of passing an array of real
53 # objects and uuids in cond[uuid_key].
54 if !cond[uuid_key].is_a? Array
55 cond[uuid_key] = [cond[uuid_key]]
57 cond[uuid_key] = cond[uuid_key].collect do |item|
58 if item.is_a? ArvadosBase
66 cond.keys.select { |x| x.match /_kind$/ }.each do |kind_key|
67 if cond[kind_key].is_a? Class
68 cond = cond.merge({ kind_key => 'arvados#' + arvados_api_client.class_kind(cond[kind_key]) })
75 api_params[:eager] = '1' if @eager
76 api_params[:limit] = @limit if @limit
77 api_params[:offset] = @offset if @offset
78 api_params[:select] = @select if @select
79 api_params[:order] = @orderby_spec if @orderby_spec
80 api_params[:filters] = @filters if @filters
81 res = arvados_api_client.api @resource_class, '', api_params
82 @results = arvados_api_client.unpack_api_response res
87 self.where({}) if !@results
107 results.collect do |m|
121 results.send('[]', *x)
137 Hash[results.collect { |x| [x.uuid, x] }]
145 results.items_available if results.respond_to? :items_available
149 results.limit if results.respond_to? :limit
153 results.offset if results.respond_to? :offset
157 results.links if results.respond_to? :links
160 # Return links provided with API response that point to the
161 # specified object, and have the specified link_class. If link_class
162 # is false or omitted, return all links pointing to the specified
164 def links_for item_or_uuid, link_class=false
165 return [] if !result_links
166 unless @links_for_uuid
168 result_links.each do |link|
169 if link.respond_to? :head_uuid
170 @links_for_uuid[link.head_uuid] ||= []
171 @links_for_uuid[link.head_uuid] << link
175 if item_or_uuid.respond_to? :uuid
176 uuid = item_or_uuid.uuid
180 (@links_for_uuid[uuid] || []).select do |link|
181 link_class == false or link.link_class == link_class
185 # Note: this arbitrarily chooses one of (possibly) multiple names.
186 def name_for item_or_uuid
187 links_for(item_or_uuid, 'name').first.andand.name