Class: Stashify::Directory::AWS::S3
- Inherits:
-
Stashify::Directory
- Object
- Stashify::Directory
- Stashify::Directory::AWS::S3
- Defined in:
- lib/stashify/directory/aws/s3.rb
Overview
An implementation for interacting with AWS S3 buckets as if they had directories with “/” as a path separator. In addition to a path, it also needs a Aws::S3::Bucket object representing the bucket the file resides within.
Instance Attribute Summary collapse
-
#bucket ⇒ Object
readonly
Returns the value of attribute bucket.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #directory(name) ⇒ Object
- #directory?(name) ⇒ Boolean
- #exists?(name) ⇒ Boolean
- #file(name) ⇒ Object
- #files ⇒ Object
-
#initialize(bucket:, path:) ⇒ S3
constructor
A new instance of S3.
- #parent ⇒ Object
Constructor Details
#initialize(bucket:, path:) ⇒ S3
Returns a new instance of S3.
16 17 18 19 |
# File 'lib/stashify/directory/aws/s3.rb', line 16 def initialize(bucket:, path:) @bucket = bucket super(path: path) end |
Instance Attribute Details
#bucket ⇒ Object (readonly)
Returns the value of attribute bucket.
14 15 16 |
# File 'lib/stashify/directory/aws/s3.rb', line 14 def bucket @bucket end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
14 15 16 |
# File 'lib/stashify/directory/aws/s3.rb', line 14 def path @path end |
Instance Method Details
#==(other) ⇒ Object
51 52 53 |
# File 'lib/stashify/directory/aws/s3.rb', line 51 def ==(other) self.class == other.class && @bucket == other.bucket && path == other.path end |
#directory(name) ⇒ Object
39 40 41 |
# File 'lib/stashify/directory/aws/s3.rb', line 39 def directory(name) Stashify::Directory::AWS::S3.new(bucket: @bucket, path: path_of(name)) end |
#directory?(name) ⇒ Boolean
35 36 37 |
# File 'lib/stashify/directory/aws/s3.rb', line 35 def directory?(name) @bucket.objects(prefix: path_of(name, "")).count.positive? end |
#exists?(name) ⇒ Boolean
43 44 45 |
# File 'lib/stashify/directory/aws/s3.rb', line 43 def exists?(name) @bucket.object(::File.join(path, name)).exists? end |
#file(name) ⇒ Object
47 48 49 |
# File 'lib/stashify/directory/aws/s3.rb', line 47 def file(name) Stashify::File::AWS::S3.new(bucket: @bucket, path: ::File.join(path, name)) end |
#files ⇒ Object
28 29 30 31 32 33 |
# File 'lib/stashify/directory/aws/s3.rb', line 28 def files @bucket.objects.map do |object| key = object.key file(::File.basename(key)) if key =~ %r{^#{Regexp.escape(path)}/([^/]*)(/.*)?$} end.compact end |