Class: Stashify::File::Google::Cloud::Storage

Inherits:
Stashify::File show all
Defined in:
lib/stashify/file/google/cloud/storage.rb

Overview

An implementation for interacting with files in Google Cloud Storage buckets. The constructor needs an instance of Google::Cloud::Storage::Bucket in order to know which bucket to interact with.

Instance Method Summary collapse

Constructor Details

#initialize(bucket:, path:) ⇒ Storage

Returns a new instance of Storage.



14
15
16
17
# File 'lib/stashify/file/google/cloud/storage.rb', line 14

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

Instance Method Details

#contentsObject



19
20
21
# File 'lib/stashify/file/google/cloud/storage.rb', line 19

def contents
  @bucket.file(path).download.string
end

#deleteObject



30
31
32
# File 'lib/stashify/file/google/cloud/storage.rb', line 30

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

#exists?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/stashify/file/google/cloud/storage.rb', line 34

def exists?
  @bucket.file(path)
end

#write(contents) ⇒ Object



23
24
25
26
27
28
# File 'lib/stashify/file/google/cloud/storage.rb', line 23

def write(contents)
  @bucket.create_file(
    StringIO.new(contents),
    path,
  )
end