Class: Xing::Services::PagedWrapper

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/xing/services/paged_wrapper.rb

Overview

If you want to use the PagedList serializers, but are using resources that aren’t actually provided by Kaminari, you can instead feed them to PagedWrapper and you should get everything you need

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(list, page_num, total_items, per_page) ⇒ PagedWrapper

Returns a new instance of PagedWrapper.



8
9
10
# File 'lib/xing/services/paged_wrapper.rb', line 8

def initialize(list, page_num, total_items, per_page)
  @list, @total_items, @per_page, @page_num = list, total_items, per_page, page_num
end

Instance Attribute Details

#listObject (readonly)

Returns the value of attribute list.



11
12
13
# File 'lib/xing/services/paged_wrapper.rb', line 11

def list
  @list
end

#page_numObject (readonly) Also known as: current_page

Returns the value of attribute page_num.



11
12
13
# File 'lib/xing/services/paged_wrapper.rb', line 11

def page_num
  @page_num
end

#per_pageObject (readonly) Also known as: limit_value

Returns the value of attribute per_page.



11
12
13
# File 'lib/xing/services/paged_wrapper.rb', line 11

def per_page
  @per_page
end

#total_itemsObject (readonly) Also known as: total_count

Returns the value of attribute total_items.



11
12
13
# File 'lib/xing/services/paged_wrapper.rb', line 11

def total_items
  @total_items
end

Instance Method Details

#each(*args, &block) ⇒ Object



21
22
23
# File 'lib/xing/services/paged_wrapper.rb', line 21

def each(*args, &block)
  @list.each(*args, &block)
end

#total_pagesObject



17
18
19
# File 'lib/xing/services/paged_wrapper.rb', line 17

def total_pages
  (total_items / per_page.to_f).ceil
end