Class: CarrierWave::Downloader::RemoteFile

Inherits:
Object
  • Object
show all
Defined in:
lib/carrierwave/downloader/remote_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ RemoteFile

Returns a new instance of RemoteFile.


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/carrierwave/downloader/remote_file.rb', line 6

def initialize(file)
  case file
  when String
    @file = StringIO.new(file)
  when Net::HTTPResponse
    @file = StringIO.new(file.body)
    @content_type = file.content_type
    @headers = file
    @uri = file.uri
  else
    @file = file
    @content_type = file.content_type
    @headers = file.meta
    @uri = file.base_uri
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*args, &block) ⇒ Object (private)


60
61
62
# File 'lib/carrierwave/downloader/remote_file.rb', line 60

def method_missing(*args, &block)
  file.send(*args, &block)
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file


4
5
6
# File 'lib/carrierwave/downloader/remote_file.rb', line 4

def file
  @file
end

#uriObject (readonly)

Returns the value of attribute uri


4
5
6
# File 'lib/carrierwave/downloader/remote_file.rb', line 4

def uri
  @uri
end

Instance Method Details

#content_typeObject


23
24
25
# File 'lib/carrierwave/downloader/remote_file.rb', line 23

def content_type
  @content_type || 'application/octet-stream'
end

#headersObject


27
28
29
# File 'lib/carrierwave/downloader/remote_file.rb', line 27

def headers
  @headers || {}
end

#original_filenameObject


31
32
33
34
35
36
37
38
39
# File 'lib/carrierwave/downloader/remote_file.rb', line 31

def original_filename
  filename = filename_from_header || filename_from_uri
  mime_type = Marcel::TYPES[content_type]
  unless File.extname(filename).present? || mime_type.blank?
    extension = mime_type[0].first
    filename = "#{filename}.#{extension}"
  end
  filename
end

#respond_to?(*args) ⇒ Boolean

Returns:

  • (Boolean)

41
42
43
# File 'lib/carrierwave/downloader/remote_file.rb', line 41

def respond_to?(*args)
  super || file.respond_to?(*args)
end