Class: Braintrust::ListObjects

Inherits:
Object
  • Object
show all
Defined in:
lib/braintrust/list_objects.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#objectsArray

Returns:

  • (Array)


6
7
8
# File 'lib/braintrust/list_objects.rb', line 6

def objects
  @objects
end

Instance Method Details

#auto_paging_each(&blk) ⇒ nil

Returns:

  • (nil)


33
34
35
36
37
38
39
40
41
42
43
# File 'lib/braintrust/list_objects.rb', line 33

def auto_paging_each(&blk)
  if !blk
    raise "A block must be given to #auto_paging_each"
  end
  page = self
  loop do
    page.objects.each { |e| blk.call(e) }
    break if !page.next_page?
    page = page.next_page
  end
end

#next_pageListObjects

Returns:



25
26
27
28
29
30
# File 'lib/braintrust/list_objects.rb', line 25

def next_page
  if !next_page?
    raise "No more pages available; please check #next_page? before calling #next_page"
  end
  client.request(Util.deep_merge(req, {query: {starting_after: objects.last.id}}), opts)
end

#next_page?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/braintrust/list_objects.rb', line 20

def next_page?
  !objects.empty?
end