Class: Gitlab::Serializer::Pagination

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/serializer/pagination.rb

Constant Summary collapse

InvalidResourceError =
Class.new(StandardError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request, response) ⇒ Pagination

Returns a new instance of Pagination.


8
9
10
11
# File 'lib/gitlab/serializer/pagination.rb', line 8

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

Instance Attribute Details

#requestObject (readonly)

Methods needed by `Gitlab::Pagination::OffsetPagination`


24
25
26
# File 'lib/gitlab/serializer/pagination.rb', line 24

def request
  @request
end

Instance Method Details

#header(header, value) ⇒ Object


30
31
32
# File 'lib/gitlab/serializer/pagination.rb', line 30

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

#paginate(resource) ⇒ Object


13
14
15
16
17
18
19
# File 'lib/gitlab/serializer/pagination.rb', line 13

def paginate(resource)
  if resource.respond_to?(:page)
    ::Gitlab::Pagination::OffsetPagination.new(self).paginate(resource)
  else
    raise InvalidResourceError
  end
end

#paramsObject


26
27
28
# File 'lib/gitlab/serializer/pagination.rb', line 26

def params
  @request.query_parameters
end