Class: E2B::BasePaginator

Inherits:
Object
  • Object
show all
Defined in:
lib/e2b/paginator.rb

Direct Known Subclasses

SandboxPaginator, SnapshotPaginator

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(limit:, next_token: nil, &fetch_page) ⇒ BasePaginator

Returns a new instance of BasePaginator.



9
10
11
12
13
14
# File 'lib/e2b/paginator.rb', line 9

def initialize(limit:, next_token: nil, &fetch_page)
  @limit = limit
  @next_token = next_token
  @fetch_page = fetch_page
  @has_next = true
end

Instance Attribute Details

#next_tokenObject (readonly)

Returns the value of attribute next_token.



7
8
9
# File 'lib/e2b/paginator.rb', line 7

def next_token
  @next_token
end

Instance Method Details

#has_next?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/e2b/paginator.rb', line 16

def has_next?
  @has_next
end

#next_itemsObject

Raises:



20
21
22
23
24
25
26
27
# File 'lib/e2b/paginator.rb', line 20

def next_items
  raise E2BError, "No more items to fetch" unless has_next?

  items, token = @fetch_page.call(limit: @limit, next_token: @next_token)
  @next_token = token
  @has_next = !@next_token.nil? && !@next_token.empty?
  items
end