Last active
December 15, 2015 16:39
-
-
Save shouichi/5290473 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Utils | |
module S3 | |
# Example | |
# Utils::S3::Bucket.all_objects_in('images') | |
module Bucket | |
class << self | |
def all_objects_in(bucket_name) | |
all_objects_from_marker(bucket_name, nil) | |
end | |
def all_objects_from_marker(bucket_name, marker) | |
bucket = AWS::S3::Bucket.find(bucket_name, marker: marker) | |
if bucket.is_truncated | |
bucket.objects.concat(all_objects_from_marker(bucket_name, bucket.objects.last.key)) | |
else | |
bucket.objects | |
end | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment