mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Restore implementation of each/all
This commit is contained in:
parent
222eddce38
commit
708fbe0a76
1 changed files with 24 additions and 10 deletions
|
@ -21,19 +21,33 @@ module Fog
|
|||
super
|
||||
end
|
||||
|
||||
# This will return a single page based on the current or provided filters,
|
||||
# updating the filters with the marker for the next page. Calling this repeatedly
|
||||
# will iterate through pages.
|
||||
# This method does NOT return all snapshots. Its implementation deliberately returns a single page
|
||||
# of results for any one call. It will return a single page based on the current or provided filters,
|
||||
# updating the filters with the marker for the next page. Calling this repeatedly will iterate
|
||||
# through pages. See the implementation of each for an example of such iteration.
|
||||
#
|
||||
# It is arguably incorrect for the method not to return all snapshots, particularly considering the
|
||||
# implementation in the corresponding 'elb' files. But this implementation has been released, and
|
||||
# backwards-compatibility requires leaving it as implemented.
|
||||
def all(filters = filters)
|
||||
self.filters.merge!(filters)
|
||||
|
||||
data = []
|
||||
begin
|
||||
result = service.describe_db_snapshots(filters).body['DescribeDBSnapshotsResult']
|
||||
self.filters[:marker] = result['Marker']
|
||||
data.concat(result['DBSnapshots'])
|
||||
end while self.filters[:marker]
|
||||
load(data)
|
||||
page = service.describe_db_snapshots(filters).body['DescribeDBSnapshotsResult']
|
||||
self.filters[:marker] = page['Marker']
|
||||
load(page['DBSnapshots'])
|
||||
end
|
||||
|
||||
# This will execute a block for each snapshot, fetching new pages of snapshots as required.
|
||||
def each(filters = filters)
|
||||
if block_given?
|
||||
begin
|
||||
page = self.all(filters)
|
||||
# We need to explicitly use the base 'each' method here on the page, otherwise we get infinite recursion
|
||||
base_each = Fog::Collection.instance_method(:each)
|
||||
base_each.bind(page).call { |snapshot| yield snapshot }
|
||||
end while self.filters[:marker]
|
||||
end
|
||||
self
|
||||
end
|
||||
|
||||
def get(identity)
|
||||
|
|
Loading…
Add table
Reference in a new issue