Class: Stashify::File::Microsoft::Azure::Storage::Blob

Inherits:
Stashify::File
  • Object
show all
Defined in:
lib/stashify/file/microsoft/azure/storage/blob.rb

Overview

An implementation for interacting with files in Azure Blob Storage. The constructor needs an instance of Azure::Storage::Blob::BlobService and Azure::Storage::Blob::Container::Container in order to know which bucket to interact with.

Instance Method Summary collapse

Constructor Details

#initialize(client:, container:, path:) ⇒ Blob

Returns a new instance of Blob.



16
17
18
19
20
# File 'lib/stashify/file/microsoft/azure/storage/blob.rb', line 16

def initialize(client:, container:, path:)
  @client = client
  @container = container
  super(path: path)
end

Instance Method Details

#contentsObject



22
23
24
25
# File 'lib/stashify/file/microsoft/azure/storage/blob.rb', line 22

def contents
  _, content = @client.get_blob(@container.name, path)
  content
end

#deleteObject



37
38
39
# File 'lib/stashify/file/microsoft/azure/storage/blob.rb', line 37

def delete
  @client.delete_blob(@container.name, path)
end

#exists?Boolean

Returns:

  • (Boolean)


31
32
33
34
35
# File 'lib/stashify/file/microsoft/azure/storage/blob.rb', line 31

def exists?
  @client.get_blob(@container.name, path)
rescue ::Azure::Core::Http::HTTPError => e
  raise unless e.status_code == 404
end

#write(contents) ⇒ Object



27
28
29
# File 'lib/stashify/file/microsoft/azure/storage/blob.rb', line 27

def write(contents)
  @client.create_block_blob(@container.name, path, contents)
end