Class: Gitlab::Pagination::Keyset::RequestContext

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/pagination/keyset/request_context.rb

Constant Summary collapse

DEFAULT_SORT_DIRECTION =
:desc
PRIMARY_KEY =
:id
TIE_BREAKER =

A tie breaker is added as an additional order-by column to establish a well-defined order. We use the primary key column here.

{ PRIMARY_KEY => DEFAULT_SORT_DIRECTION }.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request) ⇒ RequestContext

Returns a new instance of RequestContext.


17
18
19
# File 'lib/gitlab/pagination/keyset/request_context.rb', line 17

def initialize(request)
  @request = request
end

Instance Attribute Details

#requestObject (readonly)

Returns the value of attribute request


7
8
9
# File 'lib/gitlab/pagination/keyset/request_context.rb', line 7

def request
  @request
end

Instance Method Details

#apply_headers(next_page) ⇒ Object


26
27
28
29
30
31
32
# File 'lib/gitlab/pagination/keyset/request_context.rb', line 26

def apply_headers(next_page)
  Gitlab::Pagination::Keyset::HeaderBuilder
    .new(request)
    .add_next_page_header(
      query_params_for(next_page)
    )
end

#pageObject

extracts Paging information from request parameters


22
23
24
# File 'lib/gitlab/pagination/keyset/request_context.rb', line 22

def page
  @page ||= Page.new(order_by: order_by, per_page: params[:per_page])
end