You are viewing documentation for version 1 of the AWS SDK for Ruby. Version 2 documentation can be found here.

Class: AWS::Core::PageResult

Inherits:
Array
  • Object
show all
Defined in:
lib/aws/core/page_result.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(collection, items, per_page, next_token) ⇒ PageResult

Returns a new instance of PageResult

Parameters:

  • collection (Collection)

    The collection that was used to request this page of results. The collection should respond to

    page and accept a :next_token option.

  • items (Array)

    An array of result items that represent a page of results.

  • per_page (Integer)

    The number of requested items for this page of results. If the count of items is smaller than per_page then this is the last page of results.

  • next_token (String)

    (nil) A token that can be passed to the



46
47
48
49
50
51
# File 'lib/aws/core/page_result.rb', line 46

def initialize collection, items, per_page, next_token
  @collection = collection
  @per_page = per_page
  @next_token = next_token
  super(items)
end

Instance Attribute Details

#collectionCollection (readonly)

Returns the collection that was used to populated this page of results.

Returns:

  • (Collection)

    Returns the collection that was used to populated this page of results.



20
21
22
# File 'lib/aws/core/page_result.rb', line 20

def collection
  @collection
end

#next_tokenString (readonly)

Returns An opaque token that can be passed the #page method of the collection that returned this page of results. This next token behaves as a pseudo offset. If next_token is nil then there are no more results for the collection.

Returns:

  • (String)

    An opaque token that can be passed the #page method of the collection that returned this page of results. This next token behaves as a pseudo offset. If next_token is nil then there are no more results for the collection.



31
32
33
# File 'lib/aws/core/page_result.rb', line 31

def next_token
  @next_token
end

#per_pageInteger (readonly)

Returns the maximum number of results per page. The final page in a collection may return fewer than :per_page items (e.g. :per_page is 10 and there are only 7 items).

Returns:

  • (Integer)

    Returns the maximum number of results per page. The final page in a collection may return fewer than :per_page items (e.g. :per_page is 10 and there are only 7 items).



25
26
27
# File 'lib/aws/core/page_result.rb', line 25

def per_page
  @per_page
end

Instance Method Details

#last_page?Boolean

Returns true if this is the last page of results.

Returns:

  • (Boolean)

    Returns true if this is the last page of results.



64
65
66
# File 'lib/aws/core/page_result.rb', line 64

def last_page?
  next_token.nil?
end

#more?Boolean

Returns true if there are more pages of results.

Returns:

  • (Boolean)

    Returns true if there are more pages of results.



69
70
71
# File 'lib/aws/core/page_result.rb', line 69

def more?
  !!next_token
end

#next_pagePageResult

Returns:

Raises:

  • (RuntimeError)

    Raises a runtime error when called against a collection that has no more results (i.e. #last_page? == true).



56
57
58
59
60
61
# File 'lib/aws/core/page_result.rb', line 56

def next_page
  if last_page?
    raise 'unable to get the next page, already at the last page'
  end
  collection.page(:per_page => per_page, :next_token => next_token)
end