Class: Microsandbox::SandboxPage

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/microsandbox/sandbox.rb

Overview

One page of sandbox handles, returned by Microsandbox::Sandbox.list and Microsandbox::Sandbox.list_with — sandbox listing is cursor-paginated as of runtime v0.6.8. Enumerable over its SandboxHandles; fetch the following page by passing #next_cursor to Microsandbox::Sandbox.list_with.

Examples:

Walk every page

page = Microsandbox::Sandbox.list
loop do
  page.each { |h| puts h.name }
  break if page.last_page?
  page = Microsandbox::Sandbox.list_with(cursor: page.next_cursor)
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sandboxes, next_cursor) ⇒ SandboxPage

Returns a new instance of SandboxPage.



226
227
228
229
# File 'lib/microsandbox/sandbox.rb', line 226

def initialize(sandboxes, next_cursor)
  @sandboxes = sandboxes
  @next_cursor = next_cursor
end

Instance Attribute Details

#next_cursorString? (readonly)

Returns opaque cursor for the next page; nil on the final page.

Returns:

  • (String, nil)

    opaque cursor for the next page; nil on the final page



223
224
225
# File 'lib/microsandbox/sandbox.rb', line 223

def next_cursor
  @next_cursor
end

#sandboxesArray<SandboxHandle> (readonly)

Returns the sandboxes in this page.

Returns:



221
222
223
# File 'lib/microsandbox/sandbox.rb', line 221

def sandboxes
  @sandboxes
end

Instance Method Details

#eachObject



231
# File 'lib/microsandbox/sandbox.rb', line 231

def each(&) = @sandboxes.each(&)

#empty?Boolean

Returns:

  • (Boolean)


237
# File 'lib/microsandbox/sandbox.rb', line 237

def empty? = @sandboxes.empty?

#inspectObject



242
243
244
# File 'lib/microsandbox/sandbox.rb', line 242

def inspect
  "#<Microsandbox::SandboxPage size=#{size} next_cursor=#{@next_cursor.inspect}>"
end

#last_page?Boolean

Whether this is the final page (no cursor to continue from).

Returns:

  • (Boolean)


240
# File 'lib/microsandbox/sandbox.rb', line 240

def last_page? = @next_cursor.nil?

#sizeInteger Also known as: length

Returns:

  • (Integer)


234
# File 'lib/microsandbox/sandbox.rb', line 234

def size = @sandboxes.size