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
|
|
|
include ::API::Helpers::Pagination
|
|
|
|
|
|
|
|
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)
|
|
|
|
super(resource)
|
|
|
|
else
|
|
|
|
raise InvalidResourceError
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-02-06 08:47:56 -05:00
|
|
|
# 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
|