Class: Basecamp::ListEnumerator

Inherits:
Enumerator
  • Object
show all
Defined in:
lib/basecamp/list_enumerator.rb

Overview

A lazy Enumerator over paginated items that carries pagination metadata.

Behaves exactly like the plain Enumerator it replaces — each/next/peek/ take/first/lazy all work, and pages beyond the first are fetched only as iteration demands them — while additionally exposing #meta.

The metadata object is shared with the paginator: meta.total_count is populated from the eagerly fetched first page, and meta.truncated is finalized by consuming the enumeration (see ListMeta).

Re-enumerating restarts pagination: the eagerly fetched first page is served from memory on the first pass only, and later passes refetch every page for a consistent snapshot, refreshing meta from their own first-page response — metadata always describes the most recent traversal.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(meta, &block) ⇒ ListEnumerator

Returns a new instance of ListEnumerator.

Parameters:

  • meta (ListMeta)

    metadata shared with the producing paginator



24
25
26
27
# File 'lib/basecamp/list_enumerator.rb', line 24

def initialize(meta, &block)
  @meta = meta
  super(&block)
end

Instance Attribute Details

#metaListMeta (readonly)

Returns pagination metadata.

Returns:



21
22
23
# File 'lib/basecamp/list_enumerator.rb', line 21

def meta
  @meta
end