1 class ArvadosResourceList
2 include ArvadosApiClientHelper
5 def initialize resource_class=nil
6 @resource_class = resource_class
7 @fetch_multiple_pages = true
8 @arvados_api_token = Thread.current[:arvados_api_token]
9 @reader_tokens = Thread.current[:reader_tokens]
17 def limit(max_results)
18 if not max_results.nil? and not max_results.is_a? Integer
19 raise ArgumentError("argument to limit() must be an Integer or nil")
30 def order(orderby_spec)
31 @orderby_spec = orderby_spec
35 def select(columns=nil)
36 # If no column arguments were given, invoke Enumerable#select.
54 @cond.keys.each do |uuid_key|
55 if @cond[uuid_key] and (@cond[uuid_key].is_a? Array or
56 @cond[uuid_key].is_a? ArvadosBase)
57 # Coerce cond[uuid_key] to an array of uuid strings. This
58 # allows caller the convenience of passing an array of real
59 # objects and uuids in cond[uuid_key].
60 if !@cond[uuid_key].is_a? Array
61 @cond[uuid_key] = [@cond[uuid_key]]
63 @cond[uuid_key] = @cond[uuid_key].collect do |item|
64 if item.is_a? ArvadosBase
72 @cond.keys.select { |x| x.match /_kind$/ }.each do |kind_key|
73 if @cond[kind_key].is_a? Class
74 @cond = @cond.merge({ kind_key => 'arvados#' + arvados_api_client.class_kind(@cond[kind_key]) })
80 def fetch_multiple_pages(f)
81 @fetch_multiple_pages = f
97 @items_available = r.items_available if r.respond_to? :items_available
98 @result_limit = r.limit if r.respond_to? :limit
99 @result_offset = r.offset if r.respond_to? :offset
111 self.each_page do |items|
129 results.send('[]', *x)
141 Hash[self.collect { |x| [x.uuid, x] }]
160 # Obsolete method retained during api transition.
161 def links_for item_or_uuid, link_class=false
171 api_params[:where] = @cond if @cond
172 api_params[:eager] = '1' if @eager
173 api_params[:select] = @select if @select
174 api_params[:order] = @orderby_spec if @orderby_spec
175 api_params[:filters] = @filters if @filters
179 offset = @offset || 0
184 api_params[:offset] = offset
185 api_params[:limit] = (@limit - item_count) if @limit
187 res = arvados_api_client.api(@resource_class, '', api_params,
188 arvados_api_token: @arvados_api_token,
189 reader_tokens: @reader_tokens)
190 items = arvados_api_client.unpack_api_response res
192 break if items.nil? or not items.any?
194 @items_available = items.items_available if items.respond_to?(:items_available)
195 @result_limit = items.limit if (@fetch_multiple_pages == false) and items.respond_to?(:limit)
196 @result_offset = items.offset if (@fetch_multiple_pages == false) and items.respond_to?(:offset)
198 item_count += items.size
199 if items.respond_to?(:offset)
200 offset = items.offset + items.size
207 break if @limit and item_count >= @limit
208 break if items.respond_to? :items_available and offset >= items.items_available
209 end while @fetch_multiple_pages