Welcome to mirror list, hosted at ThFree Co, Russian Federation.

keyset_pagination_helpers.rb « helpers « support « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4a476c47fda46afafdd8a079b1cb95d52c384888 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# frozen_string_literal: true

module KeysetPaginationHelpers
  def pagination_links(response)
    link = response.headers['LINK']
    return unless link

    link.split(',').filter_map do |link|
      match = link.match(/<(?<url>.*)>; rel="(?<rel>\w+)"/)
      next unless match

      { url: match[:url], rel: match[:rel] }
    end
  end

  def pagination_params_from_next_url(response)
    next_link = pagination_links(response).find { |link| link[:rel] == 'next' }
    next_url = next_link&.fetch(:url)
    return unless next_url

    Rack::Utils.parse_query(URI.parse(next_url).query)
  end
end