Class: Wallaby::ModelPaginationProvider
- Inherits:
-
Object
- Object
- Wallaby::ModelPaginationProvider
- Defined in:
- lib/interfaces/wallaby/model_pagination_provider.rb
Overview
Model pagination provider interface
Direct Known Subclasses
Instance Method Summary collapse
-
#first_page? ⇒ Boolean
Check and see if it’s the first page.
-
#first_page_number ⇒ Integer
Page number of first page.
-
#from ⇒ Integer
Find out the offset ‘from`.
-
#initialize(collection, params) ⇒ ModelPaginationProvider
constructor
A new instance of ModelPaginationProvider.
-
#last_page? ⇒ Boolean
Check and see if it’s the last page.
-
#last_page_number ⇒ Integer
Page number of last page.
-
#next_page? ⇒ Boolean
Check and see if it’s the next page.
-
#next_page_number ⇒ Integer
Page number of next page.
-
#number_of_pages ⇒ Integer
Total number of pages.
-
#page_number ⇒ Integer
Find out the current page number.
-
#page_size ⇒ Integer
Find out the current page size.
-
#paginatable? ⇒ Boolean
If a collection has pagination feature.
-
#prev_page? ⇒ Boolean
Check and see if it’s the previous page.
-
#prev_page_number ⇒ Integer
Page number of previous page.
-
#to ⇒ Integer
Find out the offset ‘to`.
-
#total ⇒ Integer
Find out the total count of current query.
Constructor Details
#initialize(collection, params) ⇒ ModelPaginationProvider
Returns a new instance of ModelPaginationProvider.
8 9 10 11 |
# File 'lib/interfaces/wallaby/model_pagination_provider.rb', line 8 def initialize(collection, params) @collection = collection @params = params end |
Instance Method Details
#first_page? ⇒ Boolean
Check and see if it’s the first page
21 22 23 |
# File 'lib/interfaces/wallaby/model_pagination_provider.rb', line 21 def first_page? page_number > first_page_number end |
#first_page_number ⇒ Integer
Page number of first page
75 76 77 |
# File 'lib/interfaces/wallaby/model_pagination_provider.rb', line 75 def first_page_number 1 end |
#from ⇒ Integer
Find out the offset ‘from`
45 46 47 |
# File 'lib/interfaces/wallaby/model_pagination_provider.rb', line 45 def from total.zero? ? total : ((page_number - 1) * page_size) + 1 end |
#last_page? ⇒ Boolean
Check and see if it’s the last page
33 34 35 |
# File 'lib/interfaces/wallaby/model_pagination_provider.rb', line 33 def last_page? page_number < last_page_number end |
#last_page_number ⇒ Integer
Page number of last page
81 82 83 |
# File 'lib/interfaces/wallaby/model_pagination_provider.rb', line 81 def last_page_number number_of_pages end |
#next_page? ⇒ Boolean
Check and see if it’s the next page
39 40 41 |
# File 'lib/interfaces/wallaby/model_pagination_provider.rb', line 39 def next_page? page_number < last_page_number end |
#next_page_number ⇒ Integer
Page number of next page
93 94 95 |
# File 'lib/interfaces/wallaby/model_pagination_provider.rb', line 93 def next_page_number [page_number + 1, last_page_number].min end |
#number_of_pages ⇒ Integer
Total number of pages
99 100 101 |
# File 'lib/interfaces/wallaby/model_pagination_provider.rb', line 99 def number_of_pages (total / page_size.to_f).ceil end |
#page_number ⇒ Integer
Find out the current page number
69 70 71 |
# File 'lib/interfaces/wallaby/model_pagination_provider.rb', line 69 def page_number raise NotImplemented end |
#page_size ⇒ Integer
Find out the current page size
63 64 65 |
# File 'lib/interfaces/wallaby/model_pagination_provider.rb', line 63 def page_size raise NotImplemented end |
#paginatable? ⇒ Boolean
If a collection has pagination feature
15 16 17 |
# File 'lib/interfaces/wallaby/model_pagination_provider.rb', line 15 def paginatable? raise NotImplemented end |
#prev_page? ⇒ Boolean
Check and see if it’s the previous page
27 28 29 |
# File 'lib/interfaces/wallaby/model_pagination_provider.rb', line 27 def prev_page? page_number > first_page_number end |
#prev_page_number ⇒ Integer
Page number of previous page
87 88 89 |
# File 'lib/interfaces/wallaby/model_pagination_provider.rb', line 87 def prev_page_number [page_number - 1, first_page_number].max end |
#to ⇒ Integer
Find out the offset ‘to`
51 52 53 |
# File 'lib/interfaces/wallaby/model_pagination_provider.rb', line 51 def to [page_number * page_size, total].min end |
#total ⇒ Integer
Find out the total count of current query
57 58 59 |
# File 'lib/interfaces/wallaby/model_pagination_provider.rb', line 57 def total raise NotImplemented end |