Enables navigation of the Forge API's paginated datasets.
Default pagination limit for API request
@api private @param klass [PuppetForge::V3::Base] the class to page over @param data [Array] the current data page @param metadata [Hash<(:limit, :total, :offset)>] page metadata @param errors [Object] errors for the page request
# File lib/puppet_forge/v3/base/paginated_collection.rb, line 16 def initialize(klass, data = [], metadata = {:total => 0, :offset => 0, :limit => LIMIT}, errors = nil) super() @metadata = metadata @errors = errors @klass = klass data.each do |item| self << @klass.new(item) end end
For backwards compatibility, all returns the current object.
# File lib/puppet_forge/v3/base/paginated_collection.rb, line 28 def all self end
An enumerator that iterates over the entire collection, independent of API pagination. This will potentially result in several API requests.
@return [Enumerator] an iterator for the entire collection
# 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