class Blobby::GCSStore::StoredObject
Attributes
bucket[R]
key[R]
Public Class Methods
new(bucket, key)
click to toggle source
# File lib/blobby/gcs_store.rb, line 42 def initialize(bucket, key) @bucket = bucket @key = key end
Public Instance Methods
delete()
click to toggle source
# File lib/blobby/gcs_store.rb, line 76 def delete return false unless exists? gcs_file.delete end
exists?()
click to toggle source
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!
# File lib/blobby/gcs_store.rb, line 49 def exists? !!gcs_file&.exists? end
read() { |chunk| ... }
click to toggle source
# 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)
click to toggle source
# 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
Private Instance Methods
gcs_file()
click to toggle source
# File lib/blobby/gcs_store.rb, line 86 def gcs_file bucket.file(key) end