Class: Rage::UploadedFile

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

Overview

Models uploaded files.

The actual file is accessible via the file accessor, though some of its interface is available directly for convenience.

Rage will automatically unlink the files, so there is no need to clean them with a separate maintenance task.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file, original_filename, content_type) ⇒ UploadedFile

Returns a new instance of UploadedFile.



21
22
23
24
25
# File 'lib/rage/uploaded_file.rb', line 21

def initialize(file, original_filename, content_type)
  @file = file
  @original_filename = original_filename
  @content_type = content_type
end

Instance Attribute Details

#content_typeObject (readonly)

A string with the MIME type of the file.



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

def content_type
  @content_type
end

#fileObject (readonly) Also known as: tempfile

A File object with the actual uploaded file. Note that some of its interface is available directly.



18
19
20
# File 'lib/rage/uploaded_file.rb', line 18

def file
  @file
end

#original_filenameObject (readonly)

The basename of the file in the client.



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

def original_filename
  @original_filename
end

Instance Method Details

#close(unlink_now = false) ⇒ Object

Shortcut for file.close.



38
39
40
# File 'lib/rage/uploaded_file.rb', line 38

def close(unlink_now = false)
  @file.close(unlink_now)
end

#eof?Boolean

Shortcut for file.eof?.

Returns:

  • (Boolean)


63
64
65
# File 'lib/rage/uploaded_file.rb', line 63

def eof?
  @file.eof?
end

#openObject

Shortcut for file.open.



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

def open
  @file.open
end

#pathObject

Shortcut for file.path.



43
44
45
# File 'lib/rage/uploaded_file.rb', line 43

def path
  @file.path
end

#read(length = nil, buffer = nil) ⇒ Object

Shortcut for file.read.



28
29
30
# File 'lib/rage/uploaded_file.rb', line 28

def read(length = nil, buffer = nil)
  @file.read(length, buffer)
end

#rewindObject

Shortcut for file.rewind.



53
54
55
# File 'lib/rage/uploaded_file.rb', line 53

def rewind
  @file.rewind
end

#sizeObject

Shortcut for file.size.



58
59
60
# File 'lib/rage/uploaded_file.rb', line 58

def size
  @file.size
end

#to_ioObject



67
68
69
# File 'lib/rage/uploaded_file.rb', line 67

def to_io
  @file.to_io
end

#to_pathObject

Shortcut for file.to_path.



48
49
50
# File 'lib/rage/uploaded_file.rb', line 48

def to_path
  @file.to_path
end