Module: ApiPagination
- Defined in:
- lib/api-pagination.rb,
lib/api-pagination/hooks.rb,
lib/api-pagination/version.rb
Defined Under Namespace
Constant Summary collapse
Class Attribute Summary collapse
-
.paginator ⇒ Object
readonly
Returns the value of attribute paginator.
Class Method Summary collapse
- .pages_from(collection) ⇒ Object
- .paginate(collection, options = {}) ⇒ Object
- .total_from(collection) ⇒ Object
Class Attribute Details
.paginator ⇒ Object (readonly)
Returns the value of attribute paginator.
6 7 8 |
# File 'lib/api-pagination.rb', line 6 def paginator @paginator end |
Class Method Details
.pages_from(collection) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/api-pagination.rb', line 21 def pages_from(collection) {}.tap do |pages| unless collection.first_page? pages[:first] = 1 pages[:prev] = collection.current_page - 1 end unless collection.last_page? pages[:last] = collection.total_pages pages[:next] = collection.current_page + 1 end end end |
.paginate(collection, options = {}) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/api-pagination.rb', line 8 def paginate(collection, = {}) [:page] ||= 1 [:per_page] ||= 25 case ApiPagination.paginator when :kaminari collection = Kaminari.paginate_array(collection) if collection.is_a?(Array) collection.page([:page]).per([:per_page]) when :will_paginate collection.paginate(:page => [:page], :per_page => [:per_page]) end end |
.total_from(collection) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/api-pagination.rb', line 35 def total_from(collection) case ApiPagination.paginator when :kaminari then collection.total_count.to_s when :will_paginate then collection.total_entries.to_s end end |