Class: Sunspot::NullResult::PaginatedNullArray
- Inherits:
-
Array
- Object
- Array
- Sunspot::NullResult::PaginatedNullArray
- Defined in:
- lib/sunspot/null_result/paginated_null_array.rb
Overview
Implements the interface of github.com/sunspot/sunspot/blob/master/sunspot_rails/lib/sunspot/rails/stub_session_proxy.rb
Instance Attribute Summary collapse
-
#per_page ⇒ Object
(also: #limit_value)
readonly
Returns the value of attribute per_page.
Instance Method Summary collapse
- #current_page ⇒ Object
- #first_page? ⇒ Boolean
-
#initialize(collection, current_page: 1, per_page: 1, offset: nil) ⇒ PaginatedNullArray
constructor
A new instance of PaginatedNullArray.
- #last_page? ⇒ Boolean
- #next_page ⇒ Object
- #offset ⇒ Object
- #out_of_bounds? ⇒ Boolean
- #prev_page ⇒ Object
- #size ⇒ Object (also: #total_count)
- #total_pages ⇒ Object (also: #num_pages)
Constructor Details
#initialize(collection, current_page: 1, per_page: 1, offset: nil) ⇒ PaginatedNullArray
Returns a new instance of PaginatedNullArray.
11 12 13 14 15 16 17 |
# File 'lib/sunspot/null_result/paginated_null_array.rb', line 11 def initialize(collection, current_page: 1, per_page: 1, offset: nil) super(collection) @current_page = current_page.to_i @per_page = per_page.to_i @offset = offset @_collection = collection end |
Instance Attribute Details
#per_page ⇒ Object (readonly) Also known as: limit_value
Returns the value of attribute per_page.
9 10 11 |
# File 'lib/sunspot/null_result/paginated_null_array.rb', line 9 def per_page @per_page end |
Instance Method Details
#current_page ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/sunspot/null_result/paginated_null_array.rb', line 39 def current_page if @_collection.respond_to?(:current_page) @_collection.current_page else @current_page end end |
#first_page? ⇒ Boolean
55 56 57 |
# File 'lib/sunspot/null_result/paginated_null_array.rb', line 55 def first_page? true end |
#last_page? ⇒ Boolean
59 60 61 |
# File 'lib/sunspot/null_result/paginated_null_array.rb', line 59 def last_page? true end |
#next_page ⇒ Object
51 52 53 |
# File 'lib/sunspot/null_result/paginated_null_array.rb', line 51 def next_page (current_page+1) if total_pages > current_page end |
#offset ⇒ Object
67 68 69 |
# File 'lib/sunspot/null_result/paginated_null_array.rb', line 67 def offset @offset || 0 end |
#out_of_bounds? ⇒ Boolean
63 64 65 |
# File 'lib/sunspot/null_result/paginated_null_array.rb', line 63 def out_of_bounds? false end |
#prev_page ⇒ Object
47 48 49 |
# File 'lib/sunspot/null_result/paginated_null_array.rb', line 47 def prev_page (current_page-1) if current_page > 1 end |
#size ⇒ Object Also known as: total_count
21 22 23 24 25 26 27 |
# File 'lib/sunspot/null_result/paginated_null_array.rb', line 21 def size if @_collection.respond_to?(:total_count) @_collection.total_count else super end end |
#total_pages ⇒ Object Also known as: num_pages
30 31 32 33 34 35 36 |
# File 'lib/sunspot/null_result/paginated_null_array.rb', line 30 def total_pages if @_collection.respond_to?(:total_pages) @_collection.total_pages else [(size/per_page.to_f).ceil, 1].max end end |