Class: Stashify::Directory::Google::Cloud::Storage
- Inherits:
-
Stashify::Directory
- Object
- Stashify::Directory
- Stashify::Directory::Google::Cloud::Storage
- Defined in:
- lib/stashify/directory/google/cloud/storage.rb
Overview
An implementation for interacting with Google Cloud Storage buckets as if they had directories with “/” as a path separator. In addition to a path, it also needs a Google::Cloud::Storage::Bucket object representing the bucket the file resides within.
Instance Attribute Summary collapse
-
#bucket ⇒ Object
readonly
Returns the value of attribute bucket.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #directory(name) ⇒ Object
- #directory?(name) ⇒ Boolean
- #exists?(name) ⇒ Boolean
- #file(name) ⇒ Object
- #files ⇒ Object
-
#initialize(bucket:, path:) ⇒ Storage
constructor
A new instance of Storage.
- #parent ⇒ Object
Constructor Details
#initialize(bucket:, path:) ⇒ Storage
Returns a new instance of Storage.
19 20 21 22 |
# File 'lib/stashify/directory/google/cloud/storage.rb', line 19 def initialize(bucket:, path:) @bucket = bucket super(path: path) end |
Instance Attribute Details
#bucket ⇒ Object (readonly)
Returns the value of attribute bucket.
17 18 19 |
# File 'lib/stashify/directory/google/cloud/storage.rb', line 17 def bucket @bucket end |
Instance Method Details
#==(other) ⇒ Object
54 55 56 |
# File 'lib/stashify/directory/google/cloud/storage.rb', line 54 def ==(other) self.class == other.class && @bucket == other.bucket && path == other.path end |
#directory(name) ⇒ Object
42 43 44 |
# File 'lib/stashify/directory/google/cloud/storage.rb', line 42 def directory(name) Stashify::Directory::Google::Cloud::Storage.new(bucket: @bucket, path: path_of(name)) end |
#directory?(name) ⇒ Boolean
37 38 39 40 |
# File 'lib/stashify/directory/google/cloud/storage.rb', line 37 def directory?(name) path = path_of(name) !@bucket.file(path) && !@bucket.files(prefix: path).empty? end |
#exists?(name) ⇒ Boolean
46 47 48 |
# File 'lib/stashify/directory/google/cloud/storage.rb', line 46 def exists?(name) @bucket.file(path_of(name)) end |
#file(name) ⇒ Object
50 51 52 |
# File 'lib/stashify/directory/google/cloud/storage.rb', line 50 def file(name) Stashify::File::Google::Cloud::Storage.new(bucket: @bucket, path: path_of(name)) end |
#files ⇒ Object
31 32 33 34 35 |
# File 'lib/stashify/directory/google/cloud/storage.rb', line 31 def files @bucket.files.map do |gcloud_file| find(::Regexp.last_match(1)) if gcloud_file.name =~ %r{^#{Regexp.escape(path)}/([^/]*)(/.*)?$} end.compact end |