Module: API::Helpers::PaginationStrategies

Included in:
API::Helpers
Defined in:
lib/api/helpers/pagination_strategies.rb

Instance Method Summary collapse

Instance Method Details

#paginate_with_strategies(relation, request_scope = nil) ⇒ Object


6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/api/helpers/pagination_strategies.rb', line 6

def paginate_with_strategies(relation, request_scope = nil)
  paginator = paginator(relation, request_scope)

  result = if block_given?
             yield(paginator.paginate(relation))
           else
             paginator.paginate(relation)
           end

  result.tap do |records, _|
    paginator.finalize(records)
  end
end

#paginator(relation, request_scope = nil) ⇒ Object


20
21
22
23
24
# File 'lib/api/helpers/pagination_strategies.rb', line 20

def paginator(relation, request_scope = nil)
  return keyset_paginator(relation) if keyset_pagination_enabled?

  offset_paginator(relation, request_scope)
end