Class: Stashify::Directory::Microsoft::Azure::Storage::Blob

Inherits:
Stashify::Directory show all
Defined in:
lib/stashify/directory/microsoft/azure/storage/blob.rb

Overview

An implementation for interacting with Azure Blob Storage as if they had directories with “/” as a path separator. In addition to a path, it also needs a Azure::Storage::Blob::BlobService and Azure::Storage::Blob::Container::Container objects representing the container the file resides within.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Blob.



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

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

Instance Attribute Details

#containerObject (readonly)

Returns the value of attribute container.



19
20
21
# File 'lib/stashify/directory/microsoft/azure/storage/blob.rb', line 19

def container
  @container
end

Instance Method Details

#==(other) ⇒ Object



81
82
83
# File 'lib/stashify/directory/microsoft/azure/storage/blob.rb', line 81

def ==(other)
  self.class == other.class && @container == other.container && path == other.path
end

#blobsObject



45
46
47
48
49
50
51
# File 'lib/stashify/directory/microsoft/azure/storage/blob.rb', line 45

def blobs
  @client.list_blobs(
    @container.name,
    prefix: path_of(""),
    delimiter: "/",
  )
end

#directory(name) ⇒ Object



61
62
63
64
65
66
67
# File 'lib/stashify/directory/microsoft/azure/storage/blob.rb', line 61

def directory(name)
  Stashify::Directory::Microsoft::Azure::Storage::Blob.new(
    client: @client,
    container: @container,
    path: ::File.join(path, name),
  )
end

#directory?(name) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
56
57
58
59
# File 'lib/stashify/directory/microsoft/azure/storage/blob.rb', line 53

def directory?(name)
  !@client.list_blobs(
    @container.name,
    prefix: path_of(name, ""),
    delimiter: "/",
  ).empty?
end

#exists?(name) ⇒ Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/stashify/directory/microsoft/azure/storage/blob.rb', line 69

def exists?(name)
  file(name).exists?
end

#file(name) ⇒ Object



73
74
75
76
77
78
79
# File 'lib/stashify/directory/microsoft/azure/storage/blob.rb', line 73

def file(name)
  Stashify::File::Microsoft::Azure::Storage::Blob.new(
    client: @client,
    container: @container,
    path: path_of(name),
  )
end

#filesObject



35
36
37
38
39
40
41
42
43
# File 'lib/stashify/directory/microsoft/azure/storage/blob.rb', line 35

def files
  blobs.map do |blob|
    Stashify::File::Microsoft::Azure::Storage::Blob.new(
      client: @client,
      container: @container,
      path: path_of(blob.name),
    )
  end
end

#parentObject



27
28
29
30
31
32
33
# File 'lib/stashify/directory/microsoft/azure/storage/blob.rb', line 27

def parent
  Stashify::Directory::Microsoft::Azure::Storage::Blob.new(
    client: @client,
    container: @container,
    path: ::File.dirname(path),
  )
end