Class: CarrierWave::Storage::Sharefile::File
- Inherits:
-
Object
- Object
- CarrierWave::Storage::Sharefile::File
- Includes:
- Utilities::Uri
- Defined in:
- lib/carrierwave/storage/sharefile.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
-
#content_type ⇒ Object
Lookup value for file content-type header.
-
#content_type=(new_content_type) ⇒ Object
Set non-default content-type header (default is file.content_type).
-
#delete ⇒ Object
Removes a file from the service.
- #filename ⇒ Object
-
#initialize(uploader, config, path, client) ⇒ File
constructor
A new instance of File.
-
#read ⇒ Object
Read content of file from service.
-
#retrieve(identifier) ⇒ Object
Retrieve file from service.
- #sharefile_attributes ⇒ Object
-
#size ⇒ Object
Return size of file body.
-
#store(file) ⇒ Object
Write file to service.
-
#url ⇒ Object
Lookup URL for the path.
Constructor Details
#initialize(uploader, config, path, client) ⇒ File
Returns a new instance of File.
45 46 47 |
# File 'lib/carrierwave/storage/sharefile.rb', line 45 def initialize(uploader, config, path, client) @uploader, @config, @path, @client = uploader, config, path, client end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
43 44 45 |
# File 'lib/carrierwave/storage/sharefile.rb', line 43 def path @path end |
Instance Method Details
#content_type ⇒ Object
Lookup value for file content-type header
Returns
- String
-
value of content-type
71 72 73 |
# File 'lib/carrierwave/storage/sharefile.rb', line 71 def content_type @content_type || file.content_type end |
#content_type=(new_content_type) ⇒ Object
Set non-default content-type header (default is file.content_type)
Returns
- String
-
returns new content type value
82 83 84 |
# File 'lib/carrierwave/storage/sharefile.rb', line 82 def content_type=(new_content_type) @content_type = new_content_type end |
#delete ⇒ Object
Removes a file from the service
Returns
- Boolean
-
true on success or raises error
118 119 120 |
# File 'lib/carrierwave/storage/sharefile.rb', line 118 def delete @client.delete_document(@path) end |
#filename ⇒ Object
49 50 51 |
# File 'lib/carrierwave/storage/sharefile.rb', line 49 def filename Pathname.new(path).basename.to_s end |
#read ⇒ Object
Read content of file from service
Returns
- String
-
contents of file
92 93 94 |
# File 'lib/carrierwave/storage/sharefile.rb', line 92 def read file end |
#retrieve(identifier) ⇒ Object
Retrieve file from service
Returns
- File
143 144 145 146 |
# File 'lib/carrierwave/storage/sharefile.rb', line 143 def retrieve(identifier) @file = @client.get_document(identifier) @file ||= @file.parsed_response end |
#sharefile_attributes ⇒ Object
107 108 109 |
# File 'lib/carrierwave/storage/sharefile.rb', line 107 def sharefile_attributes attributes end |
#size ⇒ Object
Return size of file body
Returns
- Integer
-
size of file body
103 104 105 |
# File 'lib/carrierwave/storage/sharefile.rb', line 103 def size file.content_length end |
#store(file) ⇒ Object
Write file to service
Returns
- Boolean
-
true on success or raises error
129 130 131 132 133 134 |
# File 'lib/carrierwave/storage/sharefile.rb', line 129 def store(file) sharefile_file = file.to_file @content_type ||= file.content_type root_folder = @config[:sharefile_root] @file = @client.store_document(root_folder, @path, sharefile_file) end |
#url ⇒ Object
Lookup URL for the path
Returns
- String
-
URL of the download link
60 61 62 |
# File 'lib/carrierwave/storage/sharefile.rb', line 60 def url @client.get_download_link(@path) end |