Class: Stashify::File::AWS::S3

Inherits:
Stashify::File show all
Defined in:
lib/stashify/file/aws/s3.rb

Overview

An implementation for interacting with files in AWS S3 buckets. The constructor needs an instance of Aws::S3::Bucket order to know which bucket to interact with.

Instance Method Summary collapse

Constructor Details

#initialize(bucket:, path:) ⇒ S3

Returns a new instance of S3.



12
13
14
15
# File 'lib/stashify/file/aws/s3.rb', line 12

def initialize(bucket:, path:)
  @bucket = bucket
  super(path: path)
end

Instance Method Details

#contentsObject



17
18
19
# File 'lib/stashify/file/aws/s3.rb', line 17

def contents
  @bucket.object(path).get.body.read
end

#deleteObject



25
26
27
# File 'lib/stashify/file/aws/s3.rb', line 25

def delete
  @bucket.object(path).delete
end

#exists?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/stashify/file/aws/s3.rb', line 29

def exists?
  @bucket.object(path).exists?
end

#write(contents) ⇒ Object



21
22
23
# File 'lib/stashify/file/aws/s3.rb', line 21

def write(contents)
  @bucket.object(path).put(body: contents)
end