Class: Wallaby::ModelPaginator
- Inherits:
-
Object
- Object
- Wallaby::ModelPaginator
- Extended by:
- Baseable::ClassMethods
- Defined in:
- lib/paginators/wallaby/model_paginator.rb
Overview
This is the base paginator class to provider pagination for given collection.
For best practice, please create an application paginator class (see example) to better control the functions shared between different model paginators.
Instance Attribute Summary collapse
- #model_class ⇒ Class readonly
-
#provider ⇒ ModelPaginationProvider
readonly
The instance that does the job.
Attributes included from Baseable::ClassMethods
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(model_class, collection, params) ⇒ ModelPaginator
constructor
A new instance of ModelPaginator.
-
#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.
Methods included from Baseable::ClassMethods
base_class!, base_class?, namespace, namespace=
Constructor Details
#initialize(model_class, collection, params) ⇒ ModelPaginator
Returns a new instance of ModelPaginator.
28 29 30 31 32 33 34 35 |
# File 'lib/paginators/wallaby/model_paginator.rb', line 28 def initialize(model_class, collection, params) @model_class = self.class.model_class || model_class raise ArgumentError, 'Please provide a `model_class`.' unless @model_class @collection = collection @params = params @provider = Map.pagination_provider_map(@model_class).new(@collection, @params) end |
Instance Attribute Details
#model_class ⇒ Class (readonly)
18 19 20 |
# File 'lib/paginators/wallaby/model_paginator.rb', line 18 def model_class @model_class end |
#provider ⇒ ModelPaginationProvider (readonly)
Returns the instance that does the job.
23 24 25 |
# File 'lib/paginators/wallaby/model_paginator.rb', line 23 def provider @provider end |
Instance Method Details
#first_page? ⇒ Boolean
Check and see if it’s the first page
|
# File 'lib/paginators/wallaby/model_paginator.rb', line 40
|
#first_page_number ⇒ Integer
Page number of first page
|
# File 'lib/paginators/wallaby/model_paginator.rb', line 67
|
#from ⇒ Integer
Find out the offset ‘from`
|
# File 'lib/paginators/wallaby/model_paginator.rb', line 52
|
#last_page? ⇒ Boolean
Check and see if it’s the last page
|
# File 'lib/paginators/wallaby/model_paginator.rb', line 46
|
#last_page_number ⇒ Integer
Page number of last page
|
# File 'lib/paginators/wallaby/model_paginator.rb', line 70
|
#next_page? ⇒ Boolean
Check and see if it’s the next page
|
# File 'lib/paginators/wallaby/model_paginator.rb', line 49
|
#next_page_number ⇒ Integer
Page number of next page
|
# File 'lib/paginators/wallaby/model_paginator.rb', line 76
|
#number_of_pages ⇒ Integer
Total number of pages
82 |
# File 'lib/paginators/wallaby/model_paginator.rb', line 82 delegate(*ModelPaginationProvider.instance_methods(false), to: :provider) |
#page_number ⇒ Integer
Find out the current page number
|
# File 'lib/paginators/wallaby/model_paginator.rb', line 64
|
#page_size ⇒ Integer
Find out the current page size
|
# File 'lib/paginators/wallaby/model_paginator.rb', line 61
|
#paginatable? ⇒ Boolean
If a collection has pagination feature
|
# File 'lib/paginators/wallaby/model_paginator.rb', line 37
|
#prev_page? ⇒ Boolean
Check and see if it’s the previous page
|
# File 'lib/paginators/wallaby/model_paginator.rb', line 43
|
#prev_page_number ⇒ Integer
Page number of previous page
|
# File 'lib/paginators/wallaby/model_paginator.rb', line 73
|
#to ⇒ Integer
Find out the offset ‘to`
|
# File 'lib/paginators/wallaby/model_paginator.rb', line 55
|
#total ⇒ Integer
Find out the total count of current query
|
# File 'lib/paginators/wallaby/model_paginator.rb', line 58
|