Class: Anthropic::Internal::Page
- Inherits:
-
Object
- Object
- Anthropic::Internal::Page
- Includes:
- Type::BasePage
- Defined in:
- lib/anthropic/internal/page.rb
Overview
Instance Attribute Summary collapse
Instance Method Summary collapse
- #auto_paging_each(&blk) {|| ... } ⇒ Object
-
#initialize(client:, req:, headers:, page_data:) ⇒ Page
constructor
private
A new instance of Page.
- #inspect ⇒ String private
- #next_page ⇒ self
- #next_page? ⇒ Boolean
Methods included from Type::BasePage
Constructor Details
#initialize(client:, req:, headers:, page_data:) ⇒ Page
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 Page.
74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/anthropic/internal/page.rb', line 74 def initialize(client:, req:, headers:, page_data:) super case page_data in {data: Array => data} @data = data.map { Anthropic::Internal::Type::Converter.coerce(@model, _1) } else end @has_more = page_data[:has_more] @first_id = page_data[:first_id] @last_id = page_data[:last_id] end |
Instance Attribute Details
#data ⇒ Array<generic<Elem>>?
20 21 22 |
# File 'lib/anthropic/internal/page.rb', line 20 def data @data end |
#first_id ⇒ String?
26 27 28 |
# File 'lib/anthropic/internal/page.rb', line 26 def first_id @first_id end |
#has_more ⇒ Boolean
23 24 25 |
# File 'lib/anthropic/internal/page.rb', line 23 def has_more @has_more end |
#last_id ⇒ String?
29 30 31 |
# File 'lib/anthropic/internal/page.rb', line 29 def last_id @last_id end |
Instance Method Details
#auto_paging_each(&blk) {|| ... } ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/anthropic/internal/page.rb', line 54 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.
90 91 92 93 94 95 96 |
# File 'lib/anthropic/internal/page.rb', line 90 def inspect # rubocop:disable Layout/LineLength model = Anthropic::Internal::Type::Converter.inspect(@model, depth: 1) "#<#{self.class}[#{model}]:0x#{object_id.to_s(16)} has_more=#{has_more.inspect} first_id=#{first_id.inspect} last_id=#{last_id.inspect}>" # rubocop:enable Layout/LineLength end |
#next_page ⇒ self
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/anthropic/internal/page.rb', line 38 def next_page unless next_page? = "No more pages available. Please check #next_page? before calling ##{__method__}" raise RuntimeError.new() end req = Anthropic::Internal::Util.deep_merge( @req, {query: first_id.nil? ? {after_id: last_id} : {before_id: first_id}} ) @client.request(req) end |
#next_page? ⇒ Boolean
32 33 34 |
# File 'lib/anthropic/internal/page.rb', line 32 def next_page? has_more end |