Class: Pgchief::Command::S3Upload
- Inherits:
-
Object
- Object
- Pgchief::Command::S3Upload
- Defined in:
- lib/pgchief/command/s3_upload.rb
Overview
Class to upload a file to S3
Instance Attribute Summary collapse
-
#bucket ⇒ Object
readonly
Returns the value of attribute bucket.
-
#file_name ⇒ Object
readonly
Returns the value of attribute file_name.
-
#local_location ⇒ Object
readonly
Returns the value of attribute local_location.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #configured? ⇒ Boolean
-
#initialize(local_location) ⇒ S3Upload
constructor
A new instance of S3Upload.
- #s3_location ⇒ Object
- #upload! ⇒ Object
Constructor Details
#initialize(local_location) ⇒ S3Upload
Returns a new instance of S3Upload.
9 10 11 12 |
# File 'lib/pgchief/command/s3_upload.rb', line 9 def initialize(local_location) @local_location = local_location @file_name = File.basename(local_location) end |
Instance Attribute Details
#bucket ⇒ Object (readonly)
Returns the value of attribute bucket.
7 8 9 |
# File 'lib/pgchief/command/s3_upload.rb', line 7 def bucket @bucket end |
#file_name ⇒ Object (readonly)
Returns the value of attribute file_name.
7 8 9 |
# File 'lib/pgchief/command/s3_upload.rb', line 7 def file_name @file_name end |
#local_location ⇒ Object (readonly)
Returns the value of attribute local_location.
7 8 9 |
# File 'lib/pgchief/command/s3_upload.rb', line 7 def local_location @local_location end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
7 8 9 |
# File 'lib/pgchief/command/s3_upload.rb', line 7 def path @path end |
Instance Method Details
#configured? ⇒ Boolean
28 29 30 |
# File 'lib/pgchief/command/s3_upload.rb', line 28 def configured? s3.configured? end |
#s3_location ⇒ Object
24 25 26 |
# File 'lib/pgchief/command/s3_upload.rb', line 24 def s3_location "s3://#{s3.bucket}/#{s3.path}#{file_name}" end |
#upload! ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/pgchief/command/s3_upload.rb', line 14 def upload! s3.client.put_object( bucket: s3.bucket, key: "#{s3.path}#{file_name}", body: File.open(local_location, 'rb'), acl: 'private', content_type: 'application/octet-stream' ) end |