BigW Consortium Gitlab

pagination.rb 694 Bytes
Newer Older
1 2 3
module Gitlab
  module Serializer
    class Pagination
4
      InvalidResourceError = Class.new(StandardError)
5 6 7 8 9 10 11
      include ::API::Helpers::Pagination

      def initialize(request, response)
        @request = request
        @response = response
      end

12 13 14 15 16 17 18 19
      def paginate(resource)
        if resource.respond_to?(:page)
          super(resource)
        else
          raise InvalidResourceError
        end
      end

20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
      private

      # Methods needed by `API::Helpers::Pagination`
      #

      attr_reader :request

      def params
        @request.query_parameters
      end

      def header(header, value)
        @response.headers[header] = value
      end
    end
  end
end