Class: E2B::BasePaginator
- Inherits:
-
Object
- Object
- E2B::BasePaginator
- Defined in:
- lib/e2b/paginator.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#next_token ⇒ Object
readonly
Returns the value of attribute next_token.
Instance Method Summary collapse
- #has_next? ⇒ Boolean
-
#initialize(limit:, next_token: nil, &fetch_page) ⇒ BasePaginator
constructor
A new instance of BasePaginator.
- #next_items ⇒ Object
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_token ⇒ Object (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
16 17 18 |
# File 'lib/e2b/paginator.rb', line 16 def has_next? @has_next end |
#next_items ⇒ Object
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 |