Class: Supplejack::PaginatedCollection
- Inherits:
-
Object
- Object
- Supplejack::PaginatedCollection
show all
- Defined in:
- lib/supplejack/paginated_collection.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(collection, page, per_page, total) ⇒ PaginatedCollection
Returns a new instance of PaginatedCollection.
18
19
20
21
22
23
|
# File 'lib/supplejack/paginated_collection.rb', line 18
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
#method_missing(method, *args, &block) ⇒ Object
56
57
58
|
# File 'lib/supplejack/paginated_collection.rb', line 56
def method_missing(method, *args, &block)
@collection.send(method, *args, &block)
end
|
Instance Attribute Details
#current_page ⇒ Object
Returns the value of attribute current_page.
12
13
14
|
# File 'lib/supplejack/paginated_collection.rb', line 12
def current_page
@current_page
end
|
#per_page ⇒ Object
Also known as:
limit_value
Returns the value of attribute per_page.
12
13
14
|
# File 'lib/supplejack/paginated_collection.rb', line 12
def per_page
@per_page
end
|
#total_count ⇒ Object
Also known as:
total_entries
Returns the value of attribute total_count.
13
14
15
|
# File 'lib/supplejack/paginated_collection.rb', line 13
def total_count
@total_count
end
|
Instance Method Details
#first_page? ⇒ Boolean
30
31
32
|
# File 'lib/supplejack/paginated_collection.rb', line 30
def first_page?
current_page == 1
end
|
#last_page? ⇒ Boolean
34
35
36
|
# File 'lib/supplejack/paginated_collection.rb', line 34
def last_page?
current_page >= total_pages
end
|
#next_page ⇒ Object
42
43
44
|
# File 'lib/supplejack/paginated_collection.rb', line 42
def next_page
current_page < total_pages ? (current_page + 1) : nil
end
|
#offset ⇒ Object
50
51
52
|
# File 'lib/supplejack/paginated_collection.rb', line 50
def offset
(current_page - 1) * per_page
end
|
#out_of_bounds? ⇒ Boolean
46
47
48
|
# File 'lib/supplejack/paginated_collection.rb', line 46
def out_of_bounds?
current_page > total_pages
end
|
#previous_page ⇒ Object
38
39
40
|
# File 'lib/supplejack/paginated_collection.rb', line 38
def previous_page
current_page > 1 ? (current_page - 1) : nil
end
|
#total_pages ⇒ Object
Also known as:
num_pages
25
26
27
|
# File 'lib/supplejack/paginated_collection.rb', line 25
def total_pages
(total_count.to_f / per_page).ceil
end
|