BigW Consortium Gitlab

pipeline_serializer.rb 748 Bytes
Newer Older
1
class PipelineSerializer < BaseSerializer
2
  InvalidResourceError = Class.new(StandardError)
3

4 5
  entity PipelineEntity

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

  def paginated?
11
    @paginator.present?
12 13
  end

14
  def represent(resource, opts = {})
15
    if resource.is_a?(ActiveRecord::Relation)
16
      resource = resource.includes(project: :namespace)
17 18 19
    end

    if paginated?
20
      super(@paginator.paginate(resource), opts)
21 22 23 24
    else
      super(resource, opts)
    end
  end
25 26

  def represent_status(resource)
27
    return {} unless resource.present?
28

29
    data = represent(resource, { only: [{ details: [:status] }] })
Shinya Maeda committed
30
    data.dig(:details, :status) || {}
31
  end
32
end