Class: CarrierWave::Storage::FTP::File
- Inherits:
-
Object
- Object
- CarrierWave::Storage::FTP::File
- Defined in:
- lib/carrierwave/storage/ftp.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
- #filename(options = {}) ⇒ Object
-
#initialize(uploader, base, path) ⇒ File
constructor
A new instance of File.
- #read ⇒ Object
- #size ⇒ Object
- #store(file) ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(uploader, base, path) ⇒ File
Returns a new instance of File.
20 21 22 |
# File 'lib/carrierwave/storage/ftp.rb', line 20 def initialize(uploader, base, path) @uploader, @base, @path = uploader, base, path end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
18 19 20 |
# File 'lib/carrierwave/storage/ftp.rb', line 18 def path @path end |
Instance Method Details
#content_type ⇒ Object
59 60 61 |
# File 'lib/carrierwave/storage/ftp.rb', line 59 def content_type @content_type || file.content_type end |
#content_type=(new_content_type) ⇒ Object
63 64 65 |
# File 'lib/carrierwave/storage/ftp.rb', line 63 def content_type=(new_content_type) @content_type = new_content_type end |
#delete ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/carrierwave/storage/ftp.rb', line 67 def delete connection do |ftp| ftp.chdir(::File.dirname "#{@uploader.ftp_folder}/#{path}") ftp.delete(filename) end rescue end |
#exists? ⇒ Boolean
51 52 53 |
# File 'lib/carrierwave/storage/ftp.rb', line 51 def exists? size ? true : false end |
#filename(options = {}) ⇒ Object
36 37 38 |
# File 'lib/carrierwave/storage/ftp.rb', line 36 def filename( = {}) url.gsub(/.*\/(.*?$)/, '\1') end |
#read ⇒ Object
55 56 57 |
# File 'lib/carrierwave/storage/ftp.rb', line 55 def read file.body end |
#size ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/carrierwave/storage/ftp.rb', line 40 def size size = nil connection do |ftp| ftp.chdir(::File.dirname "#{@uploader.ftp_folder}/#{path}") size = ftp.size(filename) end size end |
#store(file) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/carrierwave/storage/ftp.rb', line 24 def store(file) connection do |ftp| ftp.mkdir_p(::File.dirname "#{@uploader.ftp_folder}/#{path}") ftp.chdir(::File.dirname "#{@uploader.ftp_folder}/#{path}") ftp.put(file.path, filename) end end |
#url ⇒ Object
32 33 34 |
# File 'lib/carrierwave/storage/ftp.rb', line 32 def url "#{@uploader.ftp_url}/#{path}" end |