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
- #to_file ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(uploader, base, path) ⇒ File
Returns a new instance of 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
71 72 73 |
# File 'lib/carrierwave/storage/sftp.rb', line 71 def content_type @content_type || inferred_content_type end |
#content_type=(new_content_type) ⇒ Object
75 76 77 |
# File 'lib/carrierwave/storage/sftp.rb', line 75 def content_type=(new_content_type) @content_type = new_content_type end |
#delete ⇒ Object
79 80 81 82 83 84 |
# File 'lib/carrierwave/storage/sftp.rb', line 79 def delete connection do |sftp| sftp.remove!(full_path) end rescue end |
#exists? ⇒ Boolean
60 61 62 |
# File 'lib/carrierwave/storage/sftp.rb', line 60 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
64 65 66 67 68 69 |
# File 'lib/carrierwave/storage/sftp.rb', line 64 def read file = to_file content = file.read file.close content end |
#size ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/carrierwave/storage/sftp.rb', line 50 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 |
#to_file ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/carrierwave/storage/sftp.rb', line 39 def to_file temp_file = Tempfile.new(filename) temp_file.binmode connection do |sftp| sftp.download!(full_path, temp_file) end temp_file.open temp_file.rewind temp_file end |
#url ⇒ Object
31 32 33 |
# File 'lib/carrierwave/storage/sftp.rb', line 31 def url "#{@uploader.sftp_url}/#{path}" end |