16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/manageiq/api/common/rbac/service.rb', line 16
def self.paginate(obj, method, , *method_args)
Enumerator.new do |enum|
opts = { :limit => 10, :offset => 0 }.merge()
count = nil
fetched = 0
begin
loop do
args = [method_args, opts].flatten.compact
result = obj.send(method, *args)
count ||= result.meta.count
opts[:offset] = opts[:offset] + result.data.count
result.data.each do |element|
enum.yield element
end
fetched += result.data.count
break if count == fetched || result.data.empty?
end
rescue StandardError => e
Rails.logger.error("Exception when calling pagination on #{method} #{e}")
raise
end
end
end
|