debian-mirror-gitlab/lib/gitlab/serializer/pagination.rb

36 lines
733 B
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
module Gitlab
module Serializer
class Pagination
InvalidResourceError = Class.new(StandardError)
def initialize(request, response)
@request = request
@response = response
end
def paginate(resource)
if resource.respond_to?(:page)
2019-12-26 22:10:19 +05:30
::Gitlab::Pagination::OffsetPagination.new(self).paginate(resource)
2017-08-17 22:00:37 +05:30
else
raise InvalidResourceError
end
end
2019-12-26 22:10:19 +05:30
# Methods needed by `Gitlab::Pagination::OffsetPagination`
2017-08-17 22:00:37 +05:30
#
attr_reader :request
def params
@request.query_parameters
end
def header(header, value)
@response.headers[header] = value
end
end
end
end