add tabular /collections
[arvados.git] / app / models / orvos_resource_list.rb
1 class OrvosResourceList
2   def initialize(resource_class)
3     @resource_class = resource_class
4   end
5
6   def eager(bool=true)
7     @eager = bool
8     self
9   end
10
11   def where(cond)
12     cond = cond.dup
13     cond.keys.each do |uuid_key|
14       if cond[uuid_key] and (cond[uuid_key].is_a? Array or
15                              cond[uuid_key].is_a? OrvosBase)
16         # Coerce cond[uuid_key] to an array of uuid strings.  This
17         # allows caller the convenience of passing an array of real
18         # objects and uuids in cond[uuid_key].
19         if !cond[uuid_key].is_a? Array
20           cond[uuid_key] = [cond[uuid_key]]
21         end
22         cond[uuid_key] = cond[uuid_key].collect do |item|
23           if item.is_a? OrvosBase
24             item.uuid
25           else
26             item
27           end
28         end
29       end
30     end
31     cond.keys.select { |x| x.match /_kind$/ }.each do |kind_key|
32       if cond[kind_key].is_a? Class
33         cond = cond.merge({ kind_key => 'orvos#' + $orvos_api_client.class_kind(cond[kind_key]) })
34       end
35     end
36     res = $orvos_api_client.api @resource_class, '', {
37       _method: 'GET',
38       where: cond,
39       eager: (@eager ? '1' : '0')
40     }
41     @results = $orvos_api_client.unpack_api_response res
42   end
43
44   def all
45     res = $orvos_api_client.api @resource_class, '', {
46       _method: 'GET',
47       eager: (@eager ? '1' : '0')
48     }
49     @results = $orvos_api_client.unpack_api_response res
50   end
51
52   def to_ary
53     @results
54   end
55 end