Class: S3Wrapper
- Inherits:
-
Object
- Object
- S3Wrapper
- 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
-
#aws_access_key ⇒ Object
readonly
Returns the value of attribute aws_access_key.
-
#aws_secret_key ⇒ Object
readonly
Returns the value of attribute aws_secret_key.
-
#bucket_name ⇒ Object
readonly
Returns the value of attribute bucket_name.
-
#host_name ⇒ Object
readonly
Returns the value of attribute host_name.
-
#profile ⇒ Object
Returns the value of attribute profile.
-
#s3 ⇒ Object
readonly
Returns the value of attribute s3.
Class Method Summary collapse
Instance Method Summary collapse
- #bucket ⇒ Object
-
#initialize(profile) ⇒ S3Wrapper
constructor
A new instance of S3Wrapper.
- #profile_name ⇒ Object
- #upload_file(file) ⇒ Object
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_key ⇒ Object (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_key ⇒ Object (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_name ⇒ Object (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_name ⇒ Object (readonly)
Returns the value of attribute host_name.
7 8 9 |
# File 'lib/s3-wrapper.rb', line 7 def host_name @host_name end |
#profile ⇒ Object
Returns the value of attribute profile.
6 7 8 |
# File 'lib/s3-wrapper.rb', line 6 def profile @profile end |
#s3 ⇒ Object (readonly)
Returns the value of attribute s3.
7 8 9 |
# File 'lib/s3-wrapper.rb', line 7 def s3 @s3 end |
Class Method Details
Instance Method Details
#bucket ⇒ Object
45 46 47 |
# File 'lib/s3-wrapper.rb', line 45 def bucket @bucket ||= s3.buckets[bucket_name] end |
#profile_name ⇒ Object
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 |