Class: CarrierWave::Storage::UcloudFile
- Inherits:
-
CarrierWave::SanitizedFile
- Object
- CarrierWave::SanitizedFile
- CarrierWave::Storage::UcloudFile
- Defined in:
- lib/carrierwave/storage/ucloud_file.rb
Instance Attribute Summary collapse
-
#bucket ⇒ Object
readonly
Returns the value of attribute bucket.
-
#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
Returns.
- #headers ⇒ Object
-
#initialize(uploader, base, path) ⇒ UcloudFile
constructor
A new instance of UcloudFile.
- #read ⇒ Object
- #store(file, headers = {}) ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(uploader, base, path) ⇒ UcloudFile
Returns a new instance of UcloudFile.
6 7 8 9 10 11 |
# File 'lib/carrierwave/storage/ucloud_file.rb', line 6 def initialize(uploader, base, path) @uploader = uploader @path = path @base = base @bucket = ::CarrierWave::Ucloud::Bucket.new(uploader) end |
Instance Attribute Details
#bucket ⇒ Object (readonly)
Returns the value of attribute bucket.
4 5 6 |
# File 'lib/carrierwave/storage/ucloud_file.rb', line 4 def bucket @bucket end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
4 5 6 |
# File 'lib/carrierwave/storage/ucloud_file.rb', line 4 def path @path end |
Instance Method Details
#content_type ⇒ Object
40 41 42 |
# File 'lib/carrierwave/storage/ucloud_file.rb', line 40 def content_type headers[:content_type] end |
#content_type=(new_content_type) ⇒ Object
44 45 46 |
# File 'lib/carrierwave/storage/ucloud_file.rb', line 44 def content_type=(new_content_type) headers[:content_type] = new_content_type end |
#delete ⇒ Object
28 29 30 |
# File 'lib/carrierwave/storage/ucloud_file.rb', line 28 def delete bucket.delete(path) end |
#exists? ⇒ Boolean
Returns
- Boolean
-
Whether the file exists
18 19 20 |
# File 'lib/carrierwave/storage/ucloud_file.rb', line 18 def exists? bucket.exists?(path) end |
#headers ⇒ Object
48 49 50 |
# File 'lib/carrierwave/storage/ucloud_file.rb', line 48 def headers @headers ||= {} end |
#read ⇒ Object
22 23 24 25 26 |
# File 'lib/carrierwave/storage/ucloud_file.rb', line 22 def read response = bucket.get(path) @headers = response.headers.deep_transform_keys { |k| k.underscore.to_sym rescue key } response.body end |
#store(file, headers = {}) ⇒ Object
36 37 38 |
# File 'lib/carrierwave/storage/ucloud_file.rb', line 36 def store(file, headers = {}) bucket.put(path, file, headers) end |
#url ⇒ Object
32 33 34 |
# File 'lib/carrierwave/storage/ucloud_file.rb', line 32 def url bucket.url(path) end |