Class: Blobby::GCSStore::StoredObject

Inherits:
Object
  • Object
show all
Defined in:
lib/blobby/gcs_store.rb

Instance Method Summary collapse

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

#deleteObject



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

Returns:

  • (Boolean)


49
50
51
# File 'lib/blobby/gcs_store.rb', line 49

def exists?
  !!gcs_file&.exists?
end

#readObject



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