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)



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

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
# File 'lib/carrierwave/downloader/remote_file.rb', line 31

def original_filename
  filename = filename_from_header || filename_from_uri
  mime_type = MiniMime.lookup_by_content_type(content_type)
  unless File.extname(filename).present? || mime_type.blank?
    filename = "#{filename}.#{mime_type.extension}"
  end
  filename
end

#respond_to?(*args) ⇒ Boolean

Returns:

  • (Boolean)


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

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