Class: Blobby::GCSStore::StoredObject
- Inherits:
-
Object
- Object
- Blobby::GCSStore::StoredObject
- Defined in:
- lib/blobby/gcs_store.rb
Instance Method Summary collapse
- #delete ⇒ Object
-
#exists? ⇒ Boolean
googleapis.dev/ruby/google-cloud-storage/latest/Google/Cloud/Storage/File.html#exists%3F-instance_method bucket.file(key) returns nil, if the file does not exist!.
-
#initialize(bucket, key) ⇒ StoredObject
constructor
A new instance of StoredObject.
- #read ⇒ Object
- #write(content) ⇒ Object
Constructor Details
#initialize(bucket, key) ⇒ StoredObject
Returns a new instance of StoredObject.
42 43 44 45 |
# File 'lib/blobby/gcs_store.rb', line 42 def initialize(bucket, key) @bucket = bucket @key = key end |
Instance Method Details
#delete ⇒ Object
76 77 78 79 80 |
# File 'lib/blobby/gcs_store.rb', line 76 def delete return false unless exists? gcs_file.delete end |
#exists? ⇒ Boolean
googleapis.dev/ruby/google-cloud-storage/latest/Google/Cloud/Storage/File.html#exists%3F-instance_method bucket.file(key) returns nil, if the file does not exist!
49 50 51 |
# File 'lib/blobby/gcs_store.rb', line 49 def exists? !!gcs_file&.exists? end |
#read ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/blobby/gcs_store.rb', line 54 def read return nil unless exists? io = gcs_file.download if block_given? while (chunk = io.read(512)) yield chunk end nil else io.read end end |
#write(content) ⇒ Object
69 70 71 72 73 |
# File 'lib/blobby/gcs_store.rb', line 69 def write(content) content = StringIO.new(content) unless content.respond_to?(:read) bucket.create_file(content, key) nil end |