Class: Skykick::RequestPagination::ODataPagination
- Inherits:
-
Object
- Object
- Skykick::RequestPagination::ODataPagination
- Defined in:
- lib/skykick/pagination.rb
Overview
Handles OData pagination. This class maintains pagination state, including the offset, limit (page size), and total results. Since skipping pages isn't allowed by Skykick, the pagination assumes a simplified logic with a single page.
Instance Attribute Summary collapse
-
#limit ⇒ Object
readonly
Returns the value of attribute limit.
-
#offset ⇒ Object
readonly
Returns the value of attribute offset.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
Class Method Summary collapse
-
.data(body) ⇒ Hash, ...
Processes the API response body and returns it unchanged.
Instance Method Summary collapse
-
#initialize(page_size) ⇒ ODataPagination
constructor
Initializes the pagination object with the specified page size.
-
#more_pages? ⇒ Boolean
Checks if more pages are available.
-
#next_page!(data) ⇒ Object
Updates the pagination state for the next page based on the current page's data.
-
#page_options ⇒ Hash<Symbol, Integer>
Returns the pagination options to be sent as query parameters.
Constructor Details
#initialize(page_size) ⇒ ODataPagination
Initializes the pagination object with the specified page size. Assumes that pagination starts at the first page (offset 0).
31 32 33 34 35 36 |
# File 'lib/skykick/pagination.rb', line 31 def initialize(page_size) @offset = 0 @limit = page_size # Assume we have at least one page initially @total = @limit end |
Instance Attribute Details
#limit ⇒ Object (readonly)
Returns the value of attribute limit.
25 26 27 |
# File 'lib/skykick/pagination.rb', line 25 def limit @limit end |
#offset ⇒ Object (readonly)
Returns the value of attribute offset.
25 26 27 |
# File 'lib/skykick/pagination.rb', line 25 def offset @offset end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
25 26 27 |
# File 'lib/skykick/pagination.rb', line 25 def total @total end |
Class Method Details
.data(body) ⇒ Hash, ...
Processes the API response body and returns it unchanged. This method can be overridden to handle specific response parsing needs.
66 67 68 |
# File 'lib/skykick/pagination.rb', line 66 def self.data(body) body end |
Instance Method Details
#more_pages? ⇒ Boolean
Checks if more pages are available.
Since Skykick's API supports only a single page (no $skip), this method
returns true only if the offset is at its initial value (indicating the first page).
75 76 77 |
# File 'lib/skykick/pagination.rb', line 75 def more_pages? @offset.zero? end |
#next_page!(data) ⇒ Object
Updates the pagination state for the next page based on the current page's data. Skykick's API does not allow skipping, so the offset and total are adjusted based on the size of the current data.
51 52 53 54 55 56 57 58 59 |
# File 'lib/skykick/pagination.rb', line 51 def next_page!(data) # Update the total number of results based on the size of the current data set. if data.count @total = data.count else @total = 1 end @offset += @limit end |
#page_options ⇒ Hash<Symbol, Integer>
Returns the pagination options to be sent as query parameters.
Due to Skykick's limitation, only the $top parameter is included.
42 43 44 |
# File 'lib/skykick/pagination.rb', line 42 def { '$top': @limit } end |