class S3tatistic::AmazonS3

Public Class Methods

buckets() click to toggle source
# File lib/s3tatistic/amazon_s3.rb, line 9
def buckets
  ss3.buckets.map(&:name).map {|b| info(b) rescue next}.select{|b| !b.nil?}
end
eager_objects(bucket) click to toggle source
# File lib/s3tatistic/amazon_s3.rb, line 29
def eager_objects(bucket)
  eager_load = []
  bucket.objects.each { |o| eager_load << o }
  eager_load
end
files_size(objects) click to toggle source
# File lib/s3tatistic/amazon_s3.rb, line 35
def files_size(objects)
  objects.map(&:size).reduce(&:+) # yay, functional ruby
end
find_bucket(name) click to toggle source
# File lib/s3tatistic/amazon_s3.rb, line 25
def find_bucket(name)
  ss3.bucket(name)
end
info(bucket_name) click to toggle source
# File lib/s3tatistic/amazon_s3.rb, line 13
def info(bucket_name)
  bucket = find_bucket(bucket_name)
  objects = eager_objects(bucket) # AWS don't yield it correctly, so we get eager
  {
    name: bucket.name,
    created_at: bucket.creation_date,
    files_count: objects.count,
    files_size: files_size(objects),
    last_modified: last_modified(objects)
  }
end
last_modified(objects) click to toggle source
# File lib/s3tatistic/amazon_s3.rb, line 39
def last_modified(objects)
  objects.sort_by(&:last_modified).reverse.first.key
end
ss3() click to toggle source
# File lib/s3tatistic/amazon_s3.rb, line 5
def ss3 # static s3
  @@s3 ||= Aws::S3::Resource.new
end