Class: Candid::Internal::ItemIterator

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/candid/internal/iterators/item_iterator.rb

Direct Known Subclasses

CursorItemIterator, OffsetItemIterator

Instance Method Summary collapse

Instance Method Details

#each(&block) ⇒ NilClass

Iterates over each item returned by the API.

Parameters:

  • block (Proc)

    The block which each retrieved item is yielded to.

Returns:

  • (NilClass)


12
13
14
15
16
# File 'lib/candid/internal/iterators/item_iterator.rb', line 12

def each(&block)
  while (item = get_next)
    block.call(item)
  end
end

#get_nextObject

Retrieves the next item from the API.



32
33
34
35
36
37
38
# File 'lib/candid/internal/iterators/item_iterator.rb', line 32

def get_next
  item = next_item_from_cached_page
  return item if item

  load_next_page
  next_item_from_cached_page
end

#has_next?Boolean

Whether another item will be available from the API.

Returns:

  • (Boolean)


21
22
23
24
25
26
27
28
29
# File 'lib/candid/internal/iterators/item_iterator.rb', line 21

def has_next?
  load_next_page if @page.nil?
  return false if @page.nil?

  return true if any_items_in_cached_page

  load_next_page
  any_items_in_cached_page
end