2015-05-28 16:20:48 -04:00
|
|
|
module Fog
|
|
|
|
module AWS
|
|
|
|
class IAM
|
|
|
|
class PagedCollection < Fog::Collection
|
|
|
|
def self.inherited(klass)
|
|
|
|
klass.send(:attribute, :truncated, :aliases => 'IsTruncated', :type => :boolean)
|
|
|
|
klass.send(:attribute, :marker, :aliases => 'Marker')
|
|
|
|
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
|
|
|
def each_entry(*args, &block)
|
|
|
|
to_a.each(*args, &block)
|
|
|
|
end
|
|
|
|
|
2015-09-01 18:13:58 -04:00
|
|
|
def each(options={})
|
|
|
|
limit = options[:limit] || 100
|
|
|
|
|
2015-05-28 16:20:48 -04:00
|
|
|
if !block_given?
|
|
|
|
self
|
|
|
|
else
|
|
|
|
subset = dup.all
|
|
|
|
|
|
|
|
subset.each_entry { |f| yield f }
|
|
|
|
|
|
|
|
while subset.truncated
|
|
|
|
subset.
|
2015-09-01 18:13:58 -04:00
|
|
|
all(:marker => subset.marker, :limit => limit).
|
2015-05-28 16:20:48 -04:00
|
|
|
each_entry { |f| yield f }
|
|
|
|
end
|
|
|
|
|
|
|
|
self
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def page_params(options={})
|
|
|
|
marker = options.fetch(:marker) { options.fetch('Marker') { self.marker } }
|
|
|
|
limit = options.fetch(:limit) { options['MaxItems'] }
|
|
|
|
params = {}
|
|
|
|
|
|
|
|
if marker && !marker.empty?
|
|
|
|
params.merge!('Marker' => marker)
|
|
|
|
end
|
|
|
|
|
|
|
|
if limit
|
|
|
|
params.merge!('MaxItems' => limit)
|
|
|
|
end
|
|
|
|
|
|
|
|
params
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|