Module: ApiPagination
- Defined in:
- lib/api-pagination.rb,
lib/api-pagination/hooks.rb,
lib/api-pagination/version.rb
Defined Under Namespace
Constant Summary collapse
- VERSION =
Version.to_s
Class Attribute Summary collapse
-
.paginator ⇒ Object
readonly
Returns the value of attribute paginator.
Class Method Summary collapse
- .pages_from(collection) ⇒ Object
- .paginate(collection, options = {}, &block) ⇒ 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
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/api-pagination.rb', line 20 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 = {}, &block) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/api-pagination.rb', line 8 def paginate(collection, = {}, &block) [:page] ||= 1 [:per_page] ||= 10 case ApiPagination.paginator when :kaminari collection.page([:page]).per([:per_page]).tap(&block) when :will_paginate collection.paginate(:page => [:page], :per_page => [:per_page]).tap(&block) end end |
.total_from(collection) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/api-pagination.rb', line 34 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 |