Module: WithPagination

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#paginatorObject

Returns the value of attribute paginator.



4
5
6
# File 'app/serializers/concerns/with_pagination.rb', line 4

def paginator
  @paginator
end

Instance Method Details

#paginated?Boolean

Returns:

  • (Boolean)


10
11
12
# File 'app/serializers/concerns/with_pagination.rb', line 10

def paginated?
  paginator.present?
end

#represent(resource, opts = {}) ⇒ Object

super is ‘BaseSerializer#represent` here.

we shouldn’t try to paginate single resources



17
18
19
20
21
22
23
# File 'app/serializers/concerns/with_pagination.rb', line 17

def represent(resource, opts = {})
  if paginated? && resource.respond_to?(:page)
    super(paginator.paginate(resource), opts)
  else
    super(resource, opts)
  end
end

#with_pagination(request, response) ⇒ Object



6
7
8
# File 'app/serializers/concerns/with_pagination.rb', line 6

def with_pagination(request, response)
  tap { self.paginator = Gitlab::Serializer::Pagination.new(request, response) }
end