summaryrefslogtreecommitdiff
path: root/app/serializers/pipeline_serializer.rb
blob: 245298db3c37bbdf953991656a9e24e08569623a (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
25
class PipelineSerializer < BaseSerializer
  class InvalidResourceError < StandardError; end

  entity PipelineEntity

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

  def paginated?
    defined?(@paginator)
  end

  def represent(resource, opts = {})
    if resource.is_a?(ActiveRecord::Relation)
      resource = resource.includes(project: :namespace)
    end

    if paginated?
      super(@paginator.paginate(resource), opts)
    else
      super(resource, opts)
    end
  end
end