Class: MetronomeSDK::Internal::CursorPageWithoutLimit

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

Overview

Examples:

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Type::BasePage

#to_enum

Constructor Details

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

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 CursorPageWithoutLimit.

Parameters:



65
66
67
68
69
70
71
72
73
74
# File 'lib/metronome_sdk/internal/cursor_page_without_limit.rb', line 65

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

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

Instance Attribute Details

#dataArray<generic<Elem>>?

Returns:

  • (Array<generic<Elem>>, nil)


23
24
25
# File 'lib/metronome_sdk/internal/cursor_page_without_limit.rb', line 23

def data
  @data
end

#next_page_String

Returns:

  • (String)


20
21
22
# File 'lib/metronome_sdk/internal/cursor_page_without_limit.rb', line 20

def next_page_
  @next_page_
end

Instance Method Details

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

Parameters:

  • blk (Proc)

Yield Parameters:

  • (generic<Elem>)


45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/metronome_sdk/internal/cursor_page_without_limit.rb', line 45

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.

Returns:

  • (String)


79
80
81
82
83
# File 'lib/metronome_sdk/internal/cursor_page_without_limit.rb', line 79

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

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

#next_pageself

Returns:

  • (self)

Raises:

  • (MetronomeSDK::HTTP::Error)


32
33
34
35
36
37
38
39
40
# File 'lib/metronome_sdk/internal/cursor_page_without_limit.rb', line 32

def next_page
  unless next_page?
    message = "No more pages available. Please check #next_page? before calling ##{__method__}"
    raise RuntimeError.new(message)
  end

  req = MetronomeSDK::Internal::Util.deep_merge(@req, {query: {next_page: next_page_}})
  @client.request(req)
end

#next_page?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/metronome_sdk/internal/cursor_page_without_limit.rb', line 26

def next_page?
  !next_page_.to_s.empty?
end