summaryrefslogtreecommitdiff
path: root/app/serializers/pipeline_serializer.rb
blob: 7c8dfad3b4bedce6fd60acb99ad2f004f19c6d65 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class PipelineSerializer < BaseSerializer
  class InvalidResourceError < StandardError; end

  entity PipelineEntity

  def with_pagination(request, response)
    tap { @paginator = Paginator.new(request, response) }
  end

  def paginated?
    defined?(@paginator)
  end

  def represent(resource, opts = {})
    if paginated?
      raise InvalidResourceError unless resource.respond_to?(:page)

      resource = resource.includes(project: :namespace)
      super(@paginator.paginate(resource), opts)
    else
      super(resource, opts)
    end
  end
end