Class: S3Wrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/s3-wrapper.rb,
lib/s3-wrapper/profile.rb,
lib/s3-wrapper/version.rb

Defined Under Namespace

Classes: Profile

Constant Summary collapse

VERSION =
"0.1.5"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(profile) ⇒ S3Wrapper

Returns a new instance of S3Wrapper.



16
17
18
19
# 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

Instance Attribute Details

#aws_access_keyObject (readonly)

Returns the value of attribute aws_access_key.



7
8
9
# File 'lib/s3-wrapper.rb', line 7

def aws_access_key
  @aws_access_key
end

#aws_secret_keyObject (readonly)

Returns the value of attribute aws_secret_key.



7
8
9
# File 'lib/s3-wrapper.rb', line 7

def aws_secret_key
  @aws_secret_key
end

#bucket_nameObject (readonly)

Returns the value of attribute bucket_name.



7
8
9
# File 'lib/s3-wrapper.rb', line 7

def bucket_name
  @bucket_name
end

#host_nameObject (readonly)

Returns the value of attribute host_name.



7
8
9
# File 'lib/s3-wrapper.rb', line 7

def host_name
  @host_name
end

#profileObject

Returns the value of attribute profile.



6
7
8
# File 'lib/s3-wrapper.rb', line 6

def profile
  @profile
end

#s3Object (readonly)

Returns the value of attribute s3.



7
8
9
# File 'lib/s3-wrapper.rb', line 7

def s3
  @s3
end

Class Method Details

.upload_files(profile, files) ⇒ Object



9
10
11
12
13
14
# 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

Instance Method Details

#bucketObject



45
46
47
# File 'lib/s3-wrapper.rb', line 45

def bucket
  @bucket ||= s3.buckets[bucket_name]
end

#profile_nameObject



37
38
39
# File 'lib/s3-wrapper.rb', line 37

def profile_name
  profile.name
end

#upload_file(file) ⇒ Object



49
50
51
52
53
54
55
56
# 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