Class: C::Azure::Storage::Azure::File
- Inherits:
-
Object
- Object
- C::Azure::Storage::Azure::File
- Defined in:
- lib/c/azure/storage/azure.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #content_type ⇒ Object
- #content_type=(new_content_type) ⇒ Object
- #delete ⇒ Object
- #exists? ⇒ Boolean
- #extension ⇒ Object
- #filename ⇒ Object
-
#initialize(uploader, connection, path) ⇒ File
constructor
A new instance of File.
- #read ⇒ Object
- #size ⇒ Object
- #store!(file) ⇒ Object
- #url(options = {}) ⇒ Object
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
#path ⇒ Object (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_type ⇒ Object
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 |
#delete ⇒ Object
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
63 64 65 |
# File 'lib/c/azure/storage/azure.rb', line 63 def exists? blob.nil? end |
#extension ⇒ Object
75 76 77 |
# File 'lib/c/azure/storage/azure.rb', line 75 def extension @path.split('.').last end |
#filename ⇒ Object
71 72 73 |
# File 'lib/c/azure/storage/azure.rb', line 71 def filename URI.decode(url).gsub(/.*\/(.*?$)/, '\1') end |
#read ⇒ Object
50 51 52 |
# File 'lib/c/azure/storage/azure.rb', line 50 def read content end |
#size ⇒ Object
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( = {}) path = ::File.join @uploader.azure_container, @path if @uploader.asset_host "#{@uploader.asset_host}/#{path}" else @connection.generate_uri(path).to_s end end |