Class: AhoSdk::CursorPage
- Inherits:
-
Object
- Object
- AhoSdk::CursorPage
- Includes:
- Enumerable
- Defined in:
- lib/aho_sdk/cursor_page.rb
Overview
Cursor-paginated response with lazy iteration support
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#meta ⇒ Object
readonly
Returns the value of attribute meta.
Instance Method Summary collapse
-
#cursor ⇒ String?
Cursor for the current page (if provided).
-
#each {|Hash| ... } ⇒ Enumerator
Iterate through all items across all pages (lazy loading).
-
#has_more? ⇒ Boolean
True if there are more pages.
-
#initialize(data:, meta:, fetch_next:) ⇒ CursorPage
constructor
A new instance of CursorPage.
-
#next_cursor ⇒ String?
Cursor for the next page.
-
#next_page ⇒ CursorPage?
Fetch the next page.
-
#per_page ⇒ Integer
Number of items per page (if provided).
-
#size ⇒ Integer
(also: #length)
Number of items on this page.
Constructor Details
#initialize(data:, meta:, fetch_next:) ⇒ CursorPage
Returns a new instance of CursorPage.
29 30 31 32 33 |
# File 'lib/aho_sdk/cursor_page.rb', line 29 def initialize(data:, meta:, fetch_next:) @data = data @meta = @fetch_next = fetch_next end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
24 25 26 |
# File 'lib/aho_sdk/cursor_page.rb', line 24 def data @data end |
#meta ⇒ Object (readonly)
Returns the value of attribute meta.
24 25 26 |
# File 'lib/aho_sdk/cursor_page.rb', line 24 def @meta end |
Instance Method Details
#cursor ⇒ String?
Returns Cursor for the current page (if provided).
71 72 73 |
# File 'lib/aho_sdk/cursor_page.rb', line 71 def cursor [:cursor] || ["cursor"] end |
#each {|Hash| ... } ⇒ Enumerator
Iterate through all items across all pages (lazy loading)
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/aho_sdk/cursor_page.rb', line 38 def each(&block) return enum_for(:each) unless block_given? page = self loop do page.data.each(&block) page = page.next_page break if page.nil? end end |
#has_more? ⇒ Boolean
Returns true if there are more pages.
61 62 63 |
# File 'lib/aho_sdk/cursor_page.rb', line 61 def has_more? [:has_more] || ["has_more"] || false end |
#next_cursor ⇒ String?
Returns Cursor for the next page.
66 67 68 |
# File 'lib/aho_sdk/cursor_page.rb', line 66 def next_cursor [:next_cursor] || ["next_cursor"] end |
#next_page ⇒ CursorPage?
Fetch the next page
51 52 53 54 55 56 57 58 |
# File 'lib/aho_sdk/cursor_page.rb', line 51 def next_page return nil unless has_more? cursor = next_cursor return nil if cursor.nil? @fetch_next.call(cursor) end |
#per_page ⇒ Integer
Returns Number of items per page (if provided).
76 77 78 |
# File 'lib/aho_sdk/cursor_page.rb', line 76 def per_page [:per_page] || ["per_page"] end |
#size ⇒ Integer Also known as: length
Returns Number of items on this page.
81 82 83 |
# File 'lib/aho_sdk/cursor_page.rb', line 81 def size data.size end |