pipeline_serializer.rb 716 Bytes
Newer Older
Kamil Trzcinski's avatar
Kamil Trzcinski committed
1 2
class PipelineSerializer < BaseSerializer
  entity PipelineEntity
3 4 5 6 7 8 9 10 11 12 13
  include API::Helpers::Pagination
  Struct.new('Pagination', :request, :response)

  def represent(resource, opts = {})
    if paginate?
      super(paginate(resource), opts)
    else
      super(resource, opts)
    end
  end

14 15 16 17 18 19 20 21
  def paginate?
    defined?(@pagination)
  end

  def with_pagination(request, response)
    tap { @pagination = Struct::Pagination.new(request, response) }
  end

22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
  private

  # Methods needed by `API::Helpers::Pagination`
  #
  def params
    @pagination.request.query_parameters
  end

  def request
    @pagination.request
  end

  def header(header, value)
    @pagination.response.headers[header] = value
  end
Kamil Trzcinski's avatar
Kamil Trzcinski committed
37
end