gitlab-org--gitlab-foss/app/serializers/pipeline_serializer.rb

34 lines
720 B
Ruby
Raw Normal View History

class PipelineSerializer < BaseSerializer
InvalidResourceError = Class.new(StandardError)
entity PipelineEntity
def with_pagination(request, response)
tap { @paginator = Gitlab::Serializer::Pagination.new(request, response) }
end
def paginated?
@paginator.present?
end
2017-03-10 04:30:39 -05:00
def only_status
2017-03-06 10:42:39 -05:00
tap { @status_only = { only: [{ details: [:status] }] } }
end
def represent(resource, opts = {})
if resource.is_a?(ActiveRecord::Relation)
resource = resource.includes(project: :namespace)
end
if @status_only.present?
opts.merge!(@status_only)
end
if paginated?
super(@paginator.paginate(resource), opts)
else
super(resource, opts)
end
end
end