Class: Sunspot::Search::PaginatedCollection
- Inherits:
-
Object
- Object
- Sunspot::Search::PaginatedCollection
- Defined in:
- sunspot/lib/sunspot/search/paginated_collection.rb
Instance Attribute Summary (collapse)
-
- (Object) current_page
readonly
Returns the value of attribute current_page.
-
- (Object) per_page
(also: #limit_value)
readonly
Returns the value of attribute per_page.
-
- (Object) total_count
(also: #total_entries)
readonly
Returns the value of attribute total_count.
Instance Method Summary (collapse)
- - (Boolean) first_page?
-
- (PaginatedCollection) initialize(collection, page, per_page, total)
constructor
A new instance of PaginatedCollection.
- - (Boolean) last_page?
- - (Object) next_page
- - (Object) offset
- - (Boolean) out_of_bounds?
- - (Object) previous_page
- - (Object) total_pages (also: #num_pages)
Constructor Details
- (PaginatedCollection) initialize(collection, page, per_page, total)
A new instance of PaginatedCollection
11 12 13 14 15 16 |
# File 'sunspot/lib/sunspot/search/paginated_collection.rb', line 11 def initialize(collection, page, per_page, total) @collection = collection @current_page = page @per_page = per_page @total_count = total end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
- (Object) method_missing(method, *args, &block) (private)
49 50 51 |
# File 'sunspot/lib/sunspot/search/paginated_collection.rb', line 49 def method_missing(method, *args, &block) @collection.send(method, *args, &block) end |
Instance Attribute Details
- (Object) current_page (readonly)
Returns the value of attribute current_page
7 8 9 |
# File 'sunspot/lib/sunspot/search/paginated_collection.rb', line 7 def current_page @current_page end |
- (Object) per_page (readonly) Also known as: limit_value
Returns the value of attribute per_page
7 8 9 |
# File 'sunspot/lib/sunspot/search/paginated_collection.rb', line 7 def per_page @per_page end |
- (Object) total_count (readonly) Also known as: total_entries
Returns the value of attribute total_count
7 8 9 |
# File 'sunspot/lib/sunspot/search/paginated_collection.rb', line 7 def total_count @total_count end |
Instance Method Details
- (Boolean) first_page?
23 24 25 |
# File 'sunspot/lib/sunspot/search/paginated_collection.rb', line 23 def first_page? current_page == 1 end |
- (Boolean) last_page?
27 28 29 |
# File 'sunspot/lib/sunspot/search/paginated_collection.rb', line 27 def last_page? current_page >= total_pages end |
- (Object) next_page
35 36 37 |
# File 'sunspot/lib/sunspot/search/paginated_collection.rb', line 35 def next_page current_page < total_pages ? (current_page + 1) : nil end |
- (Object) offset
43 44 45 |
# File 'sunspot/lib/sunspot/search/paginated_collection.rb', line 43 def offset (current_page - 1) * per_page end |
- (Boolean) out_of_bounds?
39 40 41 |
# File 'sunspot/lib/sunspot/search/paginated_collection.rb', line 39 def out_of_bounds? current_page > total_pages end |
- (Object) previous_page
31 32 33 |
# File 'sunspot/lib/sunspot/search/paginated_collection.rb', line 31 def previous_page current_page > 1 ? (current_page - 1) : nil end |
- (Object) total_pages Also known as: num_pages
18 19 20 |
# File 'sunspot/lib/sunspot/search/paginated_collection.rb', line 18 def total_pages (total_count.to_f / per_page).ceil end |