Class: Lithic::Internal::SinglePage

Inherits:
Object
  • Object
show all
Includes:
Type::BasePage
Defined in:
lib/lithic/internal/single_page.rb

Overview

Examples:

if single_page.has_next?
  single_page = single_page.next_page
end
single_page.auto_paging_each do ||
  puts()
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Type::BasePage

#to_enum

Constructor Details

#initialize(client:, req:, headers:, page_data:) ⇒ SinglePage

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of SinglePage.



59
60
61
62
63
64
65
66
67
68
# File 'lib/lithic/internal/single_page.rb', line 59

def initialize(client:, req:, headers:, page_data:)
  super

  case page_data
  in {data: Array => data}
    @data = data.map { Lithic::Internal::Type::Converter.coerce(@model, _1) }
  else
  end
  @has_more = page_data[:has_more]
end

Instance Attribute Details

#dataArray<generic<Elem>>?



20
21
22
# File 'lib/lithic/internal/single_page.rb', line 20

def data
  @data
end

#has_moreBoolean



23
24
25
# File 'lib/lithic/internal/single_page.rb', line 23

def has_more
  @has_more
end

Instance Method Details

#auto_paging_each(&blk) {|| ... } ⇒ Object

Yield Parameters:

  • (generic<Elem>)


39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/lithic/internal/single_page.rb', line 39

def auto_paging_each(&blk)
  unless block_given?
    raise ArgumentError.new("A block must be given to ##{__method__}")
  end

  page = self
  loop do
    page.data&.each(&blk)

    break unless page.next_page?
    page = page.next_page
  end
end

#inspectString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



73
74
75
76
77
# File 'lib/lithic/internal/single_page.rb', line 73

def inspect
  model = Lithic::Internal::Type::Converter.inspect(@model, depth: 1)

  "#<#{self.class}[#{model}]:0x#{object_id.to_s(16)} has_more=#{has_more.inspect}>"
end

#next_pageself

Raises:

  • (Lithic::HTTP::Error)


32
33
34
# File 'lib/lithic/internal/single_page.rb', line 32

def next_page
  RuntimeError.new("No more pages available.")
end

#next_page?Boolean



26
27
28
# File 'lib/lithic/internal/single_page.rb', line 26

def next_page?
  has_more
end