Class: UploadedFile

Inherits:
Object
  • Object
show all
Defined in:
lib/uploaded_file.rb

Overview

Taken from: Rack::Test::UploadedFile

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, filename, content_type = "text/plain") ⇒ UploadedFile


16
17
18
19
20
21
22
# File 'lib/uploaded_file.rb', line 16

def initialize(path, filename, content_type = "text/plain")
  raise "#{path} file does not exist" unless ::File.exist?(path)

  @content_type = content_type
  @original_filename = filename || ::File.basename(path)
  @tempfile = File.new(path, 'rb')
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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

:nodoc:


30
31
32
# File 'lib/uploaded_file.rb', line 30

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

Instance Attribute Details

#content_typeObject

The content type of the “uploaded” file


14
15
16
# File 'lib/uploaded_file.rb', line 14

def content_type
  @content_type
end

#original_filenameObject (readonly)

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


8
9
10
# File 'lib/uploaded_file.rb', line 8

def original_filename
  @original_filename
end

#tempfileObject (readonly)

The tempfile


11
12
13
# File 'lib/uploaded_file.rb', line 11

def tempfile
  @tempfile
end

Instance Method Details

#pathObject Also known as: local_path


24
25
26
# File 'lib/uploaded_file.rb', line 24

def path
  @tempfile.path
end

#respond_to?(method_name, include_private = false) ⇒ Boolean

:nodoc:


34
35
36
# File 'lib/uploaded_file.rb', line 34

def respond_to?(method_name, include_private = false) #:nodoc:
  @tempfile.respond_to?(method_name, include_private) || super
end