Class: CarrierWave::Storage::Roz::File
- Inherits:
-
Object
- Object
- CarrierWave::Storage::Roz::File
- Defined in:
- lib/carrierwave/storage/roz.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#uploader ⇒ Object
readonly
Returns the value of attribute uploader.
Instance Method Summary collapse
- #content_type ⇒ Object
- #delete ⇒ Object
- #filename ⇒ Object
-
#initialize(uploader, path) ⇒ File
constructor
A new instance of File.
- #length ⇒ Object (also: #content_length, #file_length, #size)
- #read ⇒ Object
- #store(file) ⇒ Object
- #url(*args) ⇒ Object
Constructor Details
#initialize(uploader, path) ⇒ File
Returns a new instance of File.
29 30 31 32 |
# File 'lib/carrierwave/storage/roz.rb', line 29 def initialize(uploader, path) @uploader = uploader @path = path end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
25 26 27 |
# File 'lib/carrierwave/storage/roz.rb', line 25 def path @path end |
#uploader ⇒ Object (readonly)
Returns the value of attribute uploader.
26 27 28 |
# File 'lib/carrierwave/storage/roz.rb', line 26 def uploader @uploader end |
Instance Method Details
#content_type ⇒ Object
73 74 75 |
# File 'lib/carrierwave/storage/roz.rb', line 73 def content_type file.content_type end |
#delete ⇒ Object
63 64 65 66 67 68 69 70 71 |
# File 'lib/carrierwave/storage/roz.rb', line 63 def delete response = client.delete(path) unless (200..208).include? response.code.to_i # json = JSON.parse(response.to_str) # TODO: try to parse and raise JSON error message raise response.to_s end end |
#filename ⇒ Object
55 56 57 |
# File 'lib/carrierwave/storage/roz.rb', line 55 def filename ::File.basename(path) end |
#length ⇒ Object Also known as: content_length, file_length, size
77 78 79 |
# File 'lib/carrierwave/storage/roz.rb', line 77 def length file.length end |
#read ⇒ Object
59 60 61 |
# File 'lib/carrierwave/storage/roz.rb', line 59 def read file.content end |
#store(file) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/carrierwave/storage/roz.rb', line 34 def store(file) response = client.upload(file, path) unless (200..208).include? response.code.to_i # json = JSON.parse(response.to_str) # TODO: try to parse and raise JSON error message raise response.to_s end end |
#url(*args) ⇒ Object
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/carrierwave/storage/roz.rb', line 44 def url(*args) if path == ::File.basename(path) # Backwards compatibility for when we were storing only the filename URI.join(uploader.files_base_url, "#{uploader.access_id.to_s}/", "#{uploader.store_dir}/", path).to_s else dirname = ::File.dirname(path) basename = [uploader.version_name, ::File.basename(path)].compact.join('_') URI.join(uploader.files_base_url, "#{dirname}/", basename).to_s end end |