Class: Turbopuffer::Internal::NamespacePage
- Inherits:
-
Object
- Object
- Turbopuffer::Internal::NamespacePage
- Includes:
- Type::BasePage
- Defined in:
- lib/turbopuffer/internal/namespace_page.rb
Overview
Instance Attribute Summary collapse
Instance Method Summary collapse
- #auto_paging_each(&blk) {|| ... } ⇒ Object
-
#initialize(client:, req:, headers:, page_data:) ⇒ NamespacePage
constructor
private
A new instance of NamespacePage.
- #inspect ⇒ String private
- #next_page ⇒ self
- #next_page? ⇒ Boolean
Methods included from Type::BasePage
Constructor Details
#initialize(client:, req:, headers:, page_data:) ⇒ NamespacePage
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 NamespacePage.
65 66 67 68 69 70 71 72 73 74 |
# File 'lib/turbopuffer/internal/namespace_page.rb', line 65 def initialize(client:, req:, headers:, page_data:) super case page_data in {namespaces: Array => namespaces} @namespaces = namespaces.map { Turbopuffer::Internal::Type::Converter.coerce(@model, _1) } else end @next_cursor = page_data[:next_cursor] end |
Instance Attribute Details
#namespaces ⇒ Array<generic<Elem>>?
20 21 22 |
# File 'lib/turbopuffer/internal/namespace_page.rb', line 20 def namespaces @namespaces end |
#next_cursor ⇒ String
23 24 25 |
# File 'lib/turbopuffer/internal/namespace_page.rb', line 23 def next_cursor @next_cursor end |
Instance Method Details
#auto_paging_each(&blk) {|| ... } ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/turbopuffer/internal/namespace_page.rb', line 45 def auto_paging_each(&blk) unless block_given? raise ArgumentError.new("A block must be given to ##{__method__}") end page = self loop do page.namespaces&.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.
79 80 81 82 83 |
# File 'lib/turbopuffer/internal/namespace_page.rb', line 79 def inspect model = Turbopuffer::Internal::Type::Converter.inspect(@model, depth: 1) "#<#{self.class}[#{model}]:0x#{object_id.to_s(16)} next_cursor=#{next_cursor.inspect}>" end |
#next_page ⇒ self
32 33 34 35 36 37 38 39 40 |
# File 'lib/turbopuffer/internal/namespace_page.rb', line 32 def next_page unless next_page? = "No more pages available. Please check #next_page? before calling ##{__method__}" raise RuntimeError.new() end req = Turbopuffer::Internal::Util.deep_merge(@req, {query: {cursor: next_cursor}}) @client.request(req) end |
#next_page? ⇒ Boolean
26 27 28 |
# File 'lib/turbopuffer/internal/namespace_page.rb', line 26 def next_page? !namespaces.to_a.empty? && !next_cursor.to_s.empty? end |