2018-11-19 21:01:13 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-02-06 08:47:56 -05:00
|
|
|
module Gitlab
|
|
|
|
module Serializer
|
|
|
|
class Pagination
|
2017-03-01 06:00:37 -05:00
|
|
|
InvalidResourceError = Class.new(StandardError)
|
2017-02-06 08:47:56 -05:00
|
|
|
|
|
|
|
def initialize(request, response)
|
|
|
|
@request = request
|
|
|
|
@response = response
|
|
|
|
end
|
|
|
|
|
2017-02-06 09:07:13 -05:00
|
|
|
def paginate(resource)
|
|
|
|
if resource.respond_to?(:page)
|
2019-10-29 05:06:10 -04:00
|
|
|
::Gitlab::Pagination::OffsetPagination.new(self).paginate(resource)
|
2017-02-06 09:07:13 -05:00
|
|
|
else
|
|
|
|
raise InvalidResourceError
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-10-29 05:06:10 -04:00
|
|
|
# Methods needed by `Gitlab::Pagination::OffsetPagination`
|
2017-02-06 08:47:56 -05:00
|
|
|
#
|
|
|
|
|
|
|
|
attr_reader :request
|
|
|
|
|
|
|
|
def params
|
|
|
|
@request.query_parameters
|
|
|
|
end
|
|
|
|
|
|
|
|
def header(header, value)
|
|
|
|
@response.headers[header] = value
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|