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
rubocop:disable Metrics/MethodLength.
- #results ⇒ Object
Constructor Details
#initialize(scope:, page_params:) ⇒ Pagination
7 8 9 10 11 12 |
# File 'lib/api_me/pagination.rb', line 7 def initialize(scope:, page_params:) self.scope = scope return unless page_params self.page_size = page_params[:size] self.page_offset = page_params[:offset] end |
Instance Attribute Details
#page_offset ⇒ Object
Returns the value of attribute page_offset.
5 6 7 |
# File 'lib/api_me/pagination.rb', line 5 def page_offset @page_offset end |
#page_size ⇒ Object
Returns the value of attribute page_size.
5 6 7 |
# File 'lib/api_me/pagination.rb', line 5 def page_size @page_size end |
#scope ⇒ Object
Returns the value of attribute scope.
5 6 7 |
# File 'lib/api_me/pagination.rb', line 5 def scope @scope end |
Instance Method Details
#page_meta ⇒ Object
rubocop:disable Metrics/MethodLength
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/api_me/pagination.rb', line 18 def # rubocop:disable Metrics/MethodLength return {} unless paging? { size: , offset: page_offset, record_count: scope.size, total_records: scope.total_count, total_pages: scope.total_pages, iteration_count_start: iteration_count_start, iteration_count_end: iteration_count_end, current_iteration_count: current_iteration_count } end |
#results ⇒ Object
14 15 16 |
# File 'lib/api_me/pagination.rb', line 14 def results paging? ? page.per.scope : scope end |