summaryrefslogtreecommitdiff
path: root/app/serializers/concerns/with_pagination.rb
blob: d29e22d67409d2197158cf0bdcb2c9d8aef2fd6a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
module WithPagination
  attr_accessor :paginator

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

  def paginated?
    paginator.present?
  end

  # super is `BaseSerializer#represent` here.
  #
  # we shouldn't try to paginate single resources
  def represent(resource, opts = {})
    if paginated? && resource.respond_to?(:page)
      super(@paginator.paginate(resource), opts)
    else
      super(resource, opts)
    end
  end
end