Class: ManageIQ::API::Common::RBAC::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/manageiq/api/common/rbac/service.rb

Class Method Summary collapse

Class Method Details

.call(klass) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/manageiq/api/common/rbac/service.rb', line 8

def self.call(klass)
  setup
  yield init(klass)
rescue RBACApiClient::ApiError => err
  Rails.logger.error("RBACApiClient::ApiError #{err.message} ")
  raise
end

.paginate(obj, method, pagination_options, *method_args) ⇒ Object



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, pagination_options, *method_args)
  Enumerator.new do |enum|
    opts = { :limit => 10, :offset => 0 }.merge(pagination_options)
    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