Class: CarrierWave::Storage::SFTP::File
- Inherits:
-
Object
- Object
- CarrierWave::Storage::SFTP::File
- Defined in:
- lib/carrierwave/storage/sftp.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
20 21 22 |
# File 'lib/carrierwave/storage/sftp.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/sftp.rb', line 18 def path @path end |
Instance Method Details
#content_type ⇒ Object
57 58 59 |
# File 'lib/carrierwave/storage/sftp.rb', line 57 def content_type @content_type || file.content_type end |
#content_type=(new_content_type) ⇒ Object
61 62 63 |
# File 'lib/carrierwave/storage/sftp.rb', line 61 def content_type=(new_content_type) @content_type = new_content_type end |
#delete ⇒ Object
65 66 67 68 69 70 |
# File 'lib/carrierwave/storage/sftp.rb', line 65 def delete connection do |sftp| sftp.remove!(full_path) end rescue end |
#exists? ⇒ Boolean
49 50 51 |
# File 'lib/carrierwave/storage/sftp.rb', line 49 def exists? size ? true : false end |
#filename(options = {}) ⇒ Object
35 36 37 |
# File 'lib/carrierwave/storage/sftp.rb', line 35 def filename( = {}) url.gsub(/.*\/(.*?$)/, '\1') end |
#read ⇒ Object
53 54 55 |
# File 'lib/carrierwave/storage/sftp.rb', line 53 def read file.body end |
#size ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/carrierwave/storage/sftp.rb', line 39 def size size = nil connection do |sftp| size = sftp.stat!(full_path).size end size end |
#store(file) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/carrierwave/storage/sftp.rb', line 24 def store(file) connection do |sftp| sftp.mkdir_p!(::File.dirname full_path) sftp.upload!(file.path, full_path) end end |
#url ⇒ Object
31 32 33 |
# File 'lib/carrierwave/storage/sftp.rb', line 31 def url "#{@uploader.sftp_url}/#{path}" end |