Class: Xing::Serializers::PagedList

Inherits:
List
  • Object
show all
Includes:
Paged
Defined in:
lib/xing/serializers/paged_list.rb

Overview

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)

Instance Method Summary collapse

Methods included from Paged

#first_link, #last_link, #page_link, #template_link, #total_pages

Methods inherited from List

#as_json_without_wrap, #item_serializer_class, #item_serializer_options, #template_link

Methods inherited from Base

#as_json_with_wrap, #root, #routes

Instance Method Details



31
32
33
34
35
36
# File 'lib/xing/serializers/paged_list.rb', line 31

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


23
24
25
# File 'lib/xing/serializers/paged_list.rb', line 23

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

#page_numObject



15
16
17
# File 'lib/xing/serializers/paged_list.rb', line 15

def page_num
  object.current_page
end


27
28
29
# File 'lib/xing/serializers/paged_list.rb', line 27

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


19
20
21
# File 'lib/xing/serializers/paged_list.rb', line 19

def self_link
    page_link(page: page_num)
end