Class: Xing::Serializers::PagedList
- Inherits:
-
List
- Object
- ActiveModel::Serializer
- Base
- List
- Xing::Serializers::PagedList
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
#links ⇒ Object
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
|
#next_link ⇒ Object
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_num ⇒ Object
15
16
17
|
# File 'lib/xing/serializers/paged_list.rb', line 15
def page_num
object.current_page
end
|
#previous_link ⇒ Object
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
|
#self_link ⇒ Object
19
20
21
|
# File 'lib/xing/serializers/paged_list.rb', line 19
def self_link
page_link(page: page_num)
end
|