Class: Dodopayments::Internal::CursorPagePagination
- Inherits:
-
Object
- Object
- Dodopayments::Internal::CursorPagePagination
- Includes:
- Type::BasePage
- Defined in:
- lib/dodopayments/internal/cursor_page_pagination.rb
Overview
Instance Attribute Summary collapse
Instance Method Summary collapse
- #auto_paging_each(&blk) {|| ... } ⇒ Object
-
#initialize(client:, req:, headers:, page_data:) ⇒ CursorPagePagination
constructor
private
A new instance of CursorPagePagination.
- #inspect ⇒ String private
- #next_page ⇒ self
- #next_page? ⇒ Boolean
Methods included from Type::BasePage
Constructor Details
#initialize(client:, req:, headers:, page_data:) ⇒ CursorPagePagination
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of CursorPagePagination.
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/dodopayments/internal/cursor_page_pagination.rb', line 68 def initialize(client:, req:, headers:, page_data:) super case page_data in {data: Array => data} @data = data.map { Dodopayments::Internal::Type::Converter.coerce(@model, _1) } else end @iterator = page_data[:iterator] @done = page_data[:done] end |
Instance Attribute Details
#data ⇒ Array<generic<Elem>>?
20 21 22 |
# File 'lib/dodopayments/internal/cursor_page_pagination.rb', line 20 def data @data end |
#done ⇒ Boolean
26 27 28 |
# File 'lib/dodopayments/internal/cursor_page_pagination.rb', line 26 def done @done end |
#iterator ⇒ String
23 24 25 |
# File 'lib/dodopayments/internal/cursor_page_pagination.rb', line 23 def iterator @iterator end |
Instance Method Details
#auto_paging_each(&blk) {|| ... } ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/dodopayments/internal/cursor_page_pagination.rb', line 48 def auto_paging_each(&blk) unless block_given? raise ArgumentError.new("A block must be given to ##{__method__}") end page = self loop do page.data&.each(&blk) break unless page.next_page? page = page.next_page end end |
#inspect ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
83 84 85 86 87 |
# File 'lib/dodopayments/internal/cursor_page_pagination.rb', line 83 def inspect model = Dodopayments::Internal::Type::Converter.inspect(@model, depth: 1) "#<#{self.class}[#{model}]:0x#{object_id.to_s(16)} iterator=#{iterator.inspect} done=#{done.inspect}>" end |
#next_page ⇒ self
35 36 37 38 39 40 41 42 43 |
# File 'lib/dodopayments/internal/cursor_page_pagination.rb', line 35 def next_page unless next_page? = "No more pages available. Please check #next_page? before calling ##{__method__}" raise RuntimeError.new() end req = Dodopayments::Internal::Util.deep_merge(@req, {query: {iterator: iterator}}) @client.request(req) end |
#next_page? ⇒ Boolean
29 30 31 |
# File 'lib/dodopayments/internal/cursor_page_pagination.rb', line 29 def next_page? done end |