class PuppetForge::V3::Base::PaginatedCollection

Enables navigation of the Forge API’s paginated datasets.

Constants

LIMIT

Default pagination limit for API request

Public Class Methods

new(klass, data = [], metadata = {:total => 0, :offset => 0, :limit => LIMIT}, errors = nil) click to toggle source

@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

Calls superclass method
# 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

Public Instance Methods

all() click to toggle source

For backwards compatibility, all returns the current object.

# File lib/puppet_forge/v3/base/paginated_collection.rb, line 28
def all
  self
end
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 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