Ruby mixin providing an enumeration mechanism, allowing the caller to iterate over all the resource instances in the list, automatically performing the necessary pagination behind the scenes.
Methods
Attributes
[RW] | next_page_proc | Proc called by #enumerate_all to provide the next 'page' of values to be enumerated through. Returns an Hoodoo::Client::AugmentedArray. |
Instance Public methods
enumerate_all()
Link
Yields each resource instance, automatically paginating through the entire set of resources.
Provide a block to process each resource instance. For example:
results = members.list(:search => { :surname => 'Smith' } ).enumerate_all do | member |
if member.platform_errors.has_errors?
.. deal with error ...
break
else
.. process member ...
end
end
Each iteration yields a Hoodoo::Client::AugmentedHash representation of the requested resource instance. The caller must check for errors on the value yielded with each iteration, as per the example above.
Source: show
# File lib/hoodoo/client/paginated_enumeration.rb, line 43 def enumerate_all raise "Must provide a block to enumerate_all" unless block_given? # The first set of results is in 'this' AugmentedArray results = self loop do if results.size > 0 if results.platform_errors.has_errors? raise 'Hoodoo::Client::PaginatedEnumeration#enumerate_all: Unexpected internal state combination of results set and results error indication' end # Yield a resource at a time to the caller # # Note: An inter-resource call in a single service returns each # resource as a Hash, which must be converted to AugmentedHash results.each do | result | yield to_augmented_hash(result) end results = next_page_proc.call() else # Return errors in an (empty) AugmentedHash if results.platform_errors.has_errors? yield copy_hash_errors_and_options( Hoodoo::Client::AugmentedHash.new, results ) end break end end end