Class: ApiMe::Pagination
- Inherits:
-
Object
- Object
- ApiMe::Pagination
- Defined in:
- lib/api_me/pagination.rb
Instance Attribute Summary collapse
-
#page_offset ⇒ Object
Returns the value of attribute page_offset.
-
#page_size ⇒ Object
Returns the value of attribute page_size.
-
#scope ⇒ Object
Returns the value of attribute scope.
Instance Method Summary collapse
-
#initialize(scope:, page_params:) ⇒ Pagination
constructor
A new instance of Pagination.
- #page_meta ⇒ Object
- #results ⇒ Object
Constructor Details
#initialize(scope:, page_params:) ⇒ Pagination
Returns a new instance of Pagination.
5 6 7 8 9 10 11 12 |
# File 'lib/api_me/pagination.rb', line 5 def initialize(scope:, page_params:) self.scope = scope if page_params self.page_size = page_params[:size] self.page_offset = page_params[:offset] end end |
Instance Attribute Details
#page_offset ⇒ Object
Returns the value of attribute page_offset.
3 4 5 |
# File 'lib/api_me/pagination.rb', line 3 def page_offset @page_offset end |
#page_size ⇒ Object
Returns the value of attribute page_size.
3 4 5 |
# File 'lib/api_me/pagination.rb', line 3 def page_size @page_size end |
#scope ⇒ Object
Returns the value of attribute scope.
3 4 5 |
# File 'lib/api_me/pagination.rb', line 3 def scope @scope end |
Instance Method Details
#page_meta ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/api_me/pagination.rb', line 18 def return Hash.new unless paging? { size: page_size.nil? ? default_page_size : page_size, offset: page_offset, record_count: scope.size, total_records: scope.total_count, total_pages: scope.total_pages } end |
#results ⇒ Object
14 15 16 |
# File 'lib/api_me/pagination.rb', line 14 def results paging? ? page.per.scope : scope end |