Class: Serializer::Pagination
- Inherits:
-
Upframework::BaseService
- Object
- Upframework::BaseService
- Serializer::Pagination
- Defined in:
- app/lib/serializer/pagination.rb
Constant Summary collapse
- DEFAULT_PAGE =
1
- DEFAULT_PER_PAGE =
20
Instance Attribute Summary collapse
-
#page ⇒ Object
Returns the value of attribute page.
-
#per_page ⇒ Object
Returns the value of attribute per_page.
-
#records ⇒ Object
Returns the value of attribute records.
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(records: [], page:, per_page:, **params) ⇒ Pagination
constructor
A new instance of Pagination.
- #paginate_scope ⇒ Object
- #result ⇒ Object
Constructor Details
#initialize(records: [], page:, per_page:, **params) ⇒ Pagination
Returns a new instance of Pagination.
7 8 9 10 11 |
# File 'app/lib/serializer/pagination.rb', line 7 def initialize(records: [], page:, per_page:, **params) @records = records @page = page @per_page = per_page end |
Instance Attribute Details
#page ⇒ Object
Returns the value of attribute page.
5 6 7 |
# File 'app/lib/serializer/pagination.rb', line 5 def page @page end |
#per_page ⇒ Object
Returns the value of attribute per_page.
5 6 7 |
# File 'app/lib/serializer/pagination.rb', line 5 def per_page @per_page end |
#records ⇒ Object
Returns the value of attribute records.
5 6 7 |
# File 'app/lib/serializer/pagination.rb', line 5 def records @records end |
Instance Method Details
#execute ⇒ Object
13 14 15 |
# File 'app/lib/serializer/pagination.rb', line 13 def execute paginate_scope end |
#paginate_scope ⇒ Object
21 22 23 24 25 |
# File 'app/lib/serializer/pagination.rb', line 21 def paginate_scope @records = records. page(page || DEFAULT_PAGE). per(per_page || DEFAULT_PER_PAGE) end |
#result ⇒ Object
17 18 19 |
# File 'app/lib/serializer/pagination.rb', line 17 def result records end |