123456789_123456789_123456789_123456789_123456789_

Class: Rack::Multipart::UploadedFile

Relationships & Source Files
Inherits: Object
Defined in: lib/rack/multipart/uploaded_file.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(filepath = nil, ct = "text/plain", bin = false, path: filepath, content_type: ct, binary: bin, filename: nil, io: nil) ⇒ UploadedFile

[ GitHub ]

  
# File 'lib/rack/multipart/uploaded_file.rb', line 16

def initialize(filepath = nil, ct = "text/plain", bin = false,
               path: filepath, content_type: ct, binary: bin, filename: nil, io: nil)
  if io
    @tempfile = io
    @original_filename = filename
  else
    raise "#{path} file does not exist" unless ::File.exist?(path)
    @original_filename = filename || ::File.basename(path)
    @tempfile = Tempfile.new([@original_filename, ::File.extname(path)], encoding: Encoding::BINARY)
    @tempfile.binmode if binary
    FileUtils.copy_file(path, @tempfile.path)
  end
  @content_type = content_type
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block)

This method is for internal use only.
[ GitHub ]

  
# File 'lib/rack/multipart/uploaded_file.rb', line 40

def method_missing(method_name, *args, &block) #:nodoc:
  @tempfile.__send__(method_name, *args, &block)
end

Instance Attribute Details

#content_type (rw)

The content type of the “uploaded” file

[ GitHub ]

  
# File 'lib/rack/multipart/uploaded_file.rb', line 14

attr_accessor :content_type

#original_filename (readonly)

The filename, not including the path, of the “uploaded” file

[ GitHub ]

  
# File 'lib/rack/multipart/uploaded_file.rb', line 11

attr_reader :original_filename

Instance Method Details

#local_path

Alias for #path.

[ GitHub ]

  
# File 'lib/rack/multipart/uploaded_file.rb', line 34

alias_method :local_path, :path

#path Also known as: #local_path

[ GitHub ]

  
# File 'lib/rack/multipart/uploaded_file.rb', line 31

def path
  @tempfile.path if @tempfile.respond_to?(:path)
end

#respond_to?(*args) ⇒ Boolean

[ GitHub ]

  
# File 'lib/rack/multipart/uploaded_file.rb', line 36

def respond_to?(*args)
  super or @tempfile.respond_to?(*args)
end