17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/chimera/finders.rb', line 17
def find_many(key_opts_arr)
found = []
threads = []
key_opts_arr = Array(key_opts_arr).collect { |e| Array(e) }
key_opts_arr.each do |key,opts|
opts ||= {}
threads << Thread.new do
if key
resp = self.connection(:riak_raw).fetch(self.to_s, key, opts)
case resp.code
when 300 then
obj = self.new({},key,false)
obj.riak_response = resp
obj.load_sibling_attributes
found << obj
when 200 then
if resp.body and yaml_hash = YAML.load(resp.body)
hash = {}
yaml_hash.each { |k,v| hash[k.to_sym] = v }
obj = self.new(hash,key,false)
obj.riak_response = resp
found << obj
else
obj = self.new({},key,false)
obj.riak_response = resp
found << obj
end
when 404 then
nil
else
raise(Chimera::Error::UnhandledRiakResponseCode.new(resp.code.to_s))
end
end
end
end
threads.each { |th| th.join }
found
end
|