Sha256: a79a8107c0cb380d4d41389fa5ca76b0ffc78ac63f600fd40432a405df669a06

Contents?: true

Size: 788 Bytes

Versions: 2

Compression:

Stored size: 788 Bytes

Contents

require 'xing/serializers/list'
require 'xing/serializers/paged'

module Xing::Serializers

  # Serializes a single page of a long paginated list. We assume the interface
  # provided by Kaminari: the object to be serialized needs to respond to:
  #
  #   current_page, limit_value, total_pages, total_count, each(and various
  #   Enumerable methods)

  class PagedList < List
    include Paged

    def page_num
      object.current_page
    end

    def next_link
      page_link({page: page_num + 1}) unless page_num == total_pages
    end

    def previous_link
      page_link({page: page_num - 1}) unless page_num == 1
    end

    def links
      super.merge(
                  :next => next_link,
                  :previous => previous_link
                 )
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
xing-backend-0.0.20 lib/xing/serializers/paged_list.rb
xing-backend-0.0.19 lib/xing/serializers/paged_list.rb