Class: CarrierWave::Storage::SFTP::File

Inherits:
Object
  • Object
show all
Defined in:
lib/carrierwave/storage/sftp.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#pathObject (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_typeObject



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

#deleteObject



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(options = {})
  url.gsub(/.*\/(.*?$)/, '\1')
end

#readObject



53
54
55
# File 'lib/carrierwave/storage/sftp.rb', line 53

def read
  file.body
end

#sizeObject



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

#urlObject



31
32
33
# File 'lib/carrierwave/storage/sftp.rb', line 31

def url
  "#{@uploader.sftp_url}/#{path}"
end