Class: PuppetForge::V3::Base::PaginatedCollection Private
- Inherits:
-
Array
- Object
- Array
- PuppetForge::V3::Base::PaginatedCollection
- Defined in:
- lib/puppet_forge/v3/base/paginated_collection.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Enables navigation of the Forge API’s paginated datasets.
Constant Summary collapse
- LIMIT =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Default pagination limit for API request
20
Instance Method Summary collapse
-
#all ⇒ Object
private
For backwards compatibility, all returns the current object.
-
#initialize(klass, data = [], metadata = {:total => 0, :offset => 0, :limit => LIMIT}, errors = nil) ⇒ PaginatedCollection
constructor
private
A new instance of PaginatedCollection.
-
#limit ⇒ Integer
The maximum size of any page in this dataset.
-
#offset ⇒ Integer
The offset for the current page.
-
#total ⇒ Integer
The size of the unpaginated dataset.
-
#unpaginated ⇒ Enumerator
private
An enumerator that iterates over the entire collection, independent of API pagination.
Constructor Details
#initialize(klass, data = [], metadata = {:total => 0, :offset => 0, :limit => LIMIT}, errors = nil) ⇒ PaginatedCollection
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 PaginatedCollection.
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/puppet_forge/v3/base/paginated_collection.rb', line 16 def initialize(klass, data = [], = {:total => 0, :offset => 0, :limit => LIMIT}, errors = nil) super() @metadata = @errors = errors @klass = klass data.each do |item| self << @klass.new(item) end end |
Instance Method Details
#all ⇒ Object
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.
For backwards compatibility, all returns the current object.
28 29 30 |
# File 'lib/puppet_forge/v3/base/paginated_collection.rb', line 28 def all self end |
#limit ⇒ Integer
Returns the maximum size of any page in this dataset.
53 54 55 |
# File 'lib/puppet_forge/v3/base/paginated_collection.rb', line 53 [ :total, :limit, :offset ].each do |info| define_method(info) { @metadata[info] } end |
#offset ⇒ Integer
Returns the offset for the current page.
53 54 55 |
# File 'lib/puppet_forge/v3/base/paginated_collection.rb', line 53 [ :total, :limit, :offset ].each do |info| define_method(info) { @metadata[info] } end |
#total ⇒ Integer
Returns the size of the unpaginated dataset.
53 54 55 |
# File 'lib/puppet_forge/v3/base/paginated_collection.rb', line 53 [ :total, :limit, :offset ].each do |info| define_method(info) { @metadata[info] } end |
#unpaginated ⇒ Enumerator
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.
An enumerator that iterates over the entire collection, independent of API pagination. This will potentially result in several API requests.
37 38 39 40 41 42 43 44 45 |
# File 'lib/puppet_forge/v3/base/paginated_collection.rb', line 37 def unpaginated page = @klass.get_collection(@metadata[:first]) Enumerator.new do |emitter| loop do page.each { |x| emitter << x } break unless page = page.next end end end |