Class: CarrierWave::Storage::FTP::File

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

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



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

#deleteObject



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

Returns:

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

#readObject



55
56
57
# File 'lib/carrierwave/storage/ftp.rb', line 55

def read
  file.body
end

#sizeObject



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

#urlObject



32
33
34
# File 'lib/carrierwave/storage/ftp.rb', line 32

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