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



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

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.



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

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.



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

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



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

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.



62
63
64
# File 'lib/aws/core/page_result.rb', line 62

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.



67
68
69
# File 'lib/aws/core/page_result.rb', line 67

def more?
  !!next_token
end

#next_pageObject



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

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