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

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

module Gitlab
  module Pagination
    module CursorBasedKeyset
      SUPPORTED_ORDERING = {
        Group => { name: :asc }
      }.freeze

      def self.available_for_type?(relation)
        SUPPORTED_ORDERING.key?(relation.klass)
      end

      def self.available?(cursor_based_request_context, relation)
        available_for_type?(relation) &&
        order_satisfied?(relation, cursor_based_request_context)
      end

      def self.order_satisfied?(relation, cursor_based_request_context)
        order_by_from_request = cursor_based_request_context.order_by

        SUPPORTED_ORDERING[relation.klass] == order_by_from_request
      end
      private_class_method :order_satisfied?
    end
  end
end