Class: Zizq::Resources::Page

Inherits:
Resource show all
Includes:
Enumerable
Defined in:
lib/zizq/resources/page.rb

Overview

Base class for paginated list responses.

Stores the raw response data and provides navigation helpers that follow pagination links through the Client.

Direct Known Subclasses

ErrorPage, JobPage

Instance Attribute Summary

Attributes inherited from Resource

#client

Instance Method Summary collapse

Methods inherited from Resource

#initialize, #inspect

Constructor Details

This class inherits a constructor from Zizq::Resources::Resource

Instance Method Details

#each(&block) ⇒ Object

Yields each item on this page. Required by Enumerable.



39
40
41
# File 'lib/zizq/resources/page.rb', line 39

def each(&block)
  items.each(&block)
end

#has_next?Boolean

Returns true if there is a next page that can be fetched.

Returns:

  • (Boolean)


44
45
46
# File 'lib/zizq/resources/page.rb', line 44

def has_next? #: () -> bool
  !!@data.dig("pages", "next")
end

#has_prev?Boolean

Returns true if there is a previous page that can be fetched.

Returns:

  • (Boolean)


49
50
51
# File 'lib/zizq/resources/page.rb', line 49

def has_prev? #: () -> bool
  !!@data.dig("pages", "prev")
end

#itemsObject

Wrapped resource objects for this page.

Raises:

  • (NotImplementedError)


23
24
25
# File 'lib/zizq/resources/page.rb', line 23

def items #: () -> Array[T]
  raise NotImplementedError, "#{self.class.name}#items must be implemented"
end

#next_pageObject

Fetch the next page, or nil if there isn’t one.



54
55
56
57
58
59
# File 'lib/zizq/resources/page.rb', line 54

def next_page #: () -> Page?
  path = @data.dig("pages", "next")
  return nil unless path

  wrap_page(client.get_path(path))
end

#prev_pageObject

Fetch the previous page, or nil if there isn’t one.



62
63
64
65
66
67
# File 'lib/zizq/resources/page.rb', line 62

def prev_page #: () -> Page?
  path = @data.dig("pages", "prev")
  return nil unless path

  wrap_page(client.get_path(path))
end

#to_hObject

Returns the underlying raw response hash.

Re-declared here because Enumerable#to_h would otherwise shadow the Resource#to_h definition.



31
32
33
# File 'lib/zizq/resources/page.rb', line 31

def to_h #: () -> Hash[String, untyped]
  @data
end