Skip to content

Instantly share code, notes, and snippets.

@shouichi
Last active December 15, 2015 16:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shouichi/5290473 to your computer and use it in GitHub Desktop.
Save shouichi/5290473 to your computer and use it in GitHub Desktop.
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