class PuppetForge::V3::Base::PaginatedCollection

A subclass of Her::Collection that enables navigation of the Forge API's paginated datasets.

Public Class Methods

new(klass, data, metadata, errors) click to toggle source

In addition to the standard Her::Collection arguments, this constructor requires a reference to the paginated class. This enables the collection to load related pages.

@api private @param klass [Her::Model] 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

Calls superclass method
# File lib/puppet_forge/v3/base/paginated_collection.rb, line 18
def initialize(klass, data, metadata, errors)
  super(data, metadata, errors)
  @klass = klass
end

Public Instance Methods

unpaginated() click to toggle source

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 28
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