2016-11-10 09:32:23 -05:00
|
|
|
class PipelineSerializer < BaseSerializer
|
2016-12-28 07:07:30 -05:00
|
|
|
class InvalidResourceError < StandardError; end
|
2016-12-07 09:22:01 -05:00
|
|
|
|
2017-01-27 08:45:56 -05:00
|
|
|
entity PipelineEntity
|
|
|
|
|
2017-02-02 08:37:11 -05:00
|
|
|
def with_pagination(request, response)
|
2017-02-06 08:47:56 -05:00
|
|
|
tap { @paginator = Gitlab::Serializer::Pagination.new(request, response) }
|
2017-02-02 08:37:11 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def paginated?
|
2017-02-07 07:13:33 -05:00
|
|
|
@paginator.present?
|
2017-02-02 08:37:11 -05:00
|
|
|
end
|
|
|
|
|
2016-12-07 09:22:01 -05:00
|
|
|
def represent(resource, opts = {})
|
2017-02-06 09:07:13 -05:00
|
|
|
if resource.is_a?(ActiveRecord::Relation)
|
2017-02-02 08:37:11 -05:00
|
|
|
resource = resource.includes(project: :namespace)
|
2017-02-06 09:07:13 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
if paginated?
|
2017-02-02 08:37:11 -05:00
|
|
|
super(@paginator.paginate(resource), opts)
|
2016-12-07 09:22:01 -05:00
|
|
|
else
|
|
|
|
super(resource, opts)
|
|
|
|
end
|
|
|
|
end
|
2016-11-10 09:32:23 -05:00
|
|
|
end
|