Class: PipelineSerializer

Inherits:
BaseSerializer show all
Includes:
WithPagination
Defined in:
app/serializers/pipeline_serializer.rb

Instance Attribute Summary

Attributes included from WithPagination

#paginator

Attributes inherited from BaseSerializer

#params

Instance Method Summary collapse

Methods included from WithPagination

#paginated?, #with_pagination

Methods inherited from BaseSerializer

entity, #initialize

Constructor Details

This class inherits a constructor from BaseSerializer

Instance Method Details

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

rubocop: disable CodeReuse/ActiveRecord


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/serializers/pipeline_serializer.rb', line 8

def represent(resource, opts = {})
  if resource.is_a?(ActiveRecord::Relation)
    resource = resource.preload(preloaded_relations)
  end

  if paginated?
    resource = paginator.paginate(resource)
  end

  if opts.delete(:preload)
    resource = Gitlab::Ci::Pipeline::Preloader.preload!(resource)
  end

  super(resource, opts)
end

#represent_stages(resource) ⇒ Object


32
33
34
35
36
37
# File 'app/serializers/pipeline_serializer.rb', line 32

def represent_stages(resource)
  return {} unless resource.present?

  data = represent(resource, { only: [{ details: [:stages] }], preload: true })
  data.dig(:details, :stages) || []
end

#represent_status(resource) ⇒ Object

rubocop: enable CodeReuse/ActiveRecord


25
26
27
28
29
30
# File 'app/serializers/pipeline_serializer.rb', line 25

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

  data = represent(resource, { only: [{ details: [:status] }] })
  data.dig(:details, :status) || {}
end