2016-11-10 09:32:23 -05:00
|
|
|
class PipelineSerializer < BaseSerializer
|
2017-03-01 06:00:37 -05:00
|
|
|
InvalidResourceError = Class.new(StandardError)
|
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
|