Class: AlgoliaSearch::Pagination::Kaminari
- Inherits:
-
Kaminari::PaginatableArray
- Object
- Kaminari::PaginatableArray
- AlgoliaSearch::Pagination::Kaminari
- Defined in:
- lib/algoliasearch/pagination/kaminari.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(array, options) ⇒ Kaminari
constructor
A new instance of Kaminari.
- #limit(num) ⇒ Object
- #offset(num) ⇒ Object
Constructor Details
#initialize(array, options) ⇒ Kaminari
Returns a new instance of Kaminari.
11 12 13 |
# File 'lib/algoliasearch/pagination/kaminari.rb', line 11 def initialize(array, ) super(array, **) end |
Class Method Details
.create(results, total_hits, options = {}) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/algoliasearch/pagination/kaminari.rb', line 26 def create(results, total_hits, = {}) offset = (([:page] - 1) * [:per_page]) array = new results, :offset => offset, :limit => [:per_page], :total_count => total_hits if array.empty? and !results.empty? # since Kaminari 0.16.0, you need to pad the results with nil values so it matches the offset param # otherwise you'll get an empty array: https://github.com/amatsuda/kaminari/commit/29fdcfa8865f2021f710adaedb41b7a7b081e34d results = ([nil] * offset) + results array = new results, :offset => offset, :limit => [:per_page], :total_count => total_hits end array end |
Instance Method Details
#limit(num) ⇒ Object
15 16 17 18 |
# File 'lib/algoliasearch/pagination/kaminari.rb', line 15 def limit(num) # noop self end |
#offset(num) ⇒ Object
20 21 22 23 |
# File 'lib/algoliasearch/pagination/kaminari.rb', line 20 def offset(num) # noop self end |