Class: Google::Genai::Pager

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/google/genai/pagers.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, request:, response:, config:, item_class:) ⇒ Pager

Returns a new instance of Pager.



10
11
12
13
# File 'lib/google/genai/pagers.rb', line 10

def initialize(name:, request:, response:, config:, item_class:)
  @item_class = item_class
  _init_page(name: name, request: request, response: response, config: config)
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



8
9
10
# File 'lib/google/genai/pagers.rb', line 8

def config
  @config
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/google/genai/pagers.rb', line 8

def name
  @name
end

#page_sizeObject (readonly)

Returns the value of attribute page_size.



8
9
10
# File 'lib/google/genai/pagers.rb', line 8

def page_size
  @page_size
end

#sdk_http_responseObject (readonly)

Returns the value of attribute sdk_http_response.



8
9
10
# File 'lib/google/genai/pagers.rb', line 8

def sdk_http_response
  @sdk_http_response
end

Instance Method Details

#each(&block) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/google/genai/pagers.rb', line 15

def each(&block)
  loop do
    @page.each(&block)
    break unless next_page_token
    next_page
  end
end

#next_pageObject

Raises:

  • (IndexError)


27
28
29
30
31
32
33
# File 'lib/google/genai/pagers.rb', line 27

def next_page
  raise IndexError, 'No more pages to fetch.' unless next_page_token

  response = @request.call(config: @config)
  _init_page(name: @name, request: @request, response: response, config: @config)
  @page
end

#pageObject



23
24
25
# File 'lib/google/genai/pagers.rb', line 23

def page
  @page
end