module ArPagination::RespondWithPage

Private Instance Methods

build_url_for(page, direction) click to toggle source
# File lib/ar_pagination/respond_with_page.rb, line 26
def build_url_for(page, direction)
  url_params = page.params_for(direction)
  url_for(url_params.reverse_merge(params)) if url_params[:cursor]
end
query_options() click to toggle source
# File lib/ar_pagination/respond_with_page.rb, line 22
def query_options
  params.slice(:count, :offset, :cursor)
end
respond_with_page(page) click to toggle source
# File lib/ar_pagination/respond_with_page.rb, line 6
def respond_with_page(page)
  render json: {
    data:  serialize_page(page),
    links: {
      first: build_url_for(page, :first),
      last:  nil, # @note find efficient way if needed
      next:  build_url_for(page, :next),
      prev:  build_url_for(page, :prev)
    }
  }
end
serialize_page(page) click to toggle source
# File lib/ar_pagination/respond_with_page.rb, line 18
def serialize_page(page)
  ActiveModel::ArraySerializer.new(page.data, url_options: url_options, scope: current_user)
end