Class: Pgchief::Command::S3Upload

Inherits:
Object
  • Object
show all
Defined in:
lib/pgchief/command/s3_upload.rb

Overview

Class to upload a file to S3

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#bucketObject (readonly)

Returns the value of attribute bucket.



7
8
9
# File 'lib/pgchief/command/s3_upload.rb', line 7

def bucket
  @bucket
end

#file_nameObject (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_locationObject (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

#pathObject (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

Returns:

  • (Boolean)


28
29
30
# File 'lib/pgchief/command/s3_upload.rb', line 28

def configured?
  s3.configured?
end

#s3_locationObject



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