class S3Wrapper

Constants

VERSION

Attributes

aws_access_key[R]
aws_secret_key[R]
bucket_name[R]
host_name[R]
profile[RW]
s3[R]

Public Class Methods

new(profile) click to toggle source
# File lib/s3-wrapper.rb, line 16
def initialize(profile)
  self.profile = profile
  AWS.config(access_key_id: aws_access_key, secret_access_key: aws_secret_key, region: 'us-west-2')
end
upload_files(profile, files) click to toggle source
# File lib/s3-wrapper.rb, line 9
def self.upload_files(profile, files)
  wrapper = S3Wrapper.new(profile)
  files.each do |file|
    wrapper.upload_file(file)
  end
end

Public Instance Methods

bucket() click to toggle source
# File lib/s3-wrapper.rb, line 45
def bucket
  @bucket ||= s3.buckets[bucket_name]
end
profile_name() click to toggle source
# File lib/s3-wrapper.rb, line 37
def profile_name
  profile.name
end
upload_file(file) click to toggle source
# File lib/s3-wrapper.rb, line 49
def upload_file(file)
  puts "Uploading #{file}"
  current_month = Time.now.strftime("%Y%m")
  key = File.basename(file)
  key = "#{host_name}/#{profile_name}/#{current_month}/#{key}"
  bucket.objects[key].delete
  bucket.objects[key].write(file: file, acl: :authenticated_read)
end