Class: C::Azure::Storage::Azure::File

Inherits:
Object
  • Object
show all
Defined in:
lib/c/azure/storage/azure.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uploader, connection, path) ⇒ File

Returns a new instance of File.



28
29
30
31
32
# File 'lib/c/azure/storage/azure.rb', line 28

def initialize(uploader, connection, path)
  @uploader = uploader
  @connection = connection
  @path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



26
27
28
# File 'lib/c/azure/storage/azure.rb', line 26

def path
  @path
end

Instance Method Details

#content_typeObject



54
55
56
57
# File 'lib/c/azure/storage/azure.rb', line 54

def content_type
  @content_type = blob.properties[:content_type] if @content_type.nil? && !blob.nil?
  @content_type
end

#content_type=(new_content_type) ⇒ Object



59
60
61
# File 'lib/c/azure/storage/azure.rb', line 59

def content_type=(new_content_type)
  @content_type = new_content_type
end

#deleteObject



79
80
81
82
83
84
85
86
# File 'lib/c/azure/storage/azure.rb', line 79

def delete
  begin
    @connection.delete_blob @uploader.azure_container, @path
    true
  rescue ::Azure::Storage::Core::StorageError
    false
  end
end

#exists?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/c/azure/storage/azure.rb', line 63

def exists?
  blob.nil?
end

#extensionObject



75
76
77
# File 'lib/c/azure/storage/azure.rb', line 75

def extension
  @path.split('.').last
end

#filenameObject



71
72
73
# File 'lib/c/azure/storage/azure.rb', line 71

def filename
  URI.decode(url).gsub(/.*\/(.*?$)/, '\1')
end

#readObject



50
51
52
# File 'lib/c/azure/storage/azure.rb', line 50

def read
  content
end

#sizeObject



67
68
69
# File 'lib/c/azure/storage/azure.rb', line 67

def size
  blob.properties[:content_length] unless blob.nil?
end

#store!(file) ⇒ Object



34
35
36
37
38
39
# File 'lib/c/azure/storage/azure.rb', line 34

def store!(file)
  @content = file.read
  @content_type = file.content_type
  @connection.create_block_blob @uploader.azure_container, @path, @content, content_type: @content_type
  true
end

#url(options = {}) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/c/azure/storage/azure.rb', line 41

def url(options = {})
  path = ::File.join @uploader.azure_container, @path
  if @uploader.asset_host
    "#{@uploader.asset_host}/#{path}"
  else
    @connection.generate_uri(path).to_s
  end
end