Class: CarrierWave::Uploader::Download::RemoteFile

Inherits:
Object
  • Object
show all
Defined in:
lib/carrierwave/uploader/download.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri, remote_headers = {}, skip_ssrf_protection: false) ⇒ RemoteFile

Returns a new instance of RemoteFile.



16
17
18
19
20
21
# File 'lib/carrierwave/uploader/download.rb', line 16

def initialize(uri, remote_headers = {}, skip_ssrf_protection: false)
  @uri = uri
  @remote_headers = remote_headers.reverse_merge('User-Agent' => "CarrierWave/#{CarrierWave::VERSION}")
  @file, @content_type, @headers = nil
  @skip_ssrf_protection = skip_ssrf_protection
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



87
88
89
# File 'lib/carrierwave/uploader/download.rb', line 87

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

Instance Attribute Details

#uriObject (readonly)

Returns the value of attribute uri.



14
15
16
# File 'lib/carrierwave/uploader/download.rb', line 14

def uri
  @uri
end

Instance Method Details

#content_typeObject



40
41
42
# File 'lib/carrierwave/uploader/download.rb', line 40

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

#headersObject



44
45
46
# File 'lib/carrierwave/uploader/download.rb', line 44

def headers
  @headers || {}
end

#http?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/carrierwave/uploader/download.rb', line 36

def http?
  @uri.scheme =~ /^https?$/
end

#original_filenameObject



23
24
25
26
27
28
29
30
# File 'lib/carrierwave/uploader/download.rb', line 23

def original_filename
  filename = filename_from_header || filename_from_uri
  mime_type = MIME::Types[content_type].first
  unless File.extname(filename).present? || mime_type.blank?
    filename = "#{filename}.#{mime_type.extensions.first}"
  end
  filename
end

#respond_to?(*args) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/carrierwave/uploader/download.rb', line 32

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