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.



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

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.



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

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.



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

def file
  @file
end

#original_filenameObject (readonly)

The basename of the file in the client.



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

def original_filename
  @original_filename
end

Instance Method Details

#closeObject

Shortcut for file.close.



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

def close
  @file.close
end

#eof?Boolean

Shortcut for file.eof?.

Returns:

  • (Boolean)


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

def eof?
  @file.eof?
end

#pathObject

Shortcut for file.path.



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

def path
  @file.path
end

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

Shortcut for file.read.



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

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

#rewindObject

Shortcut for file.rewind.



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

def rewind
  @file.rewind
end

#sizeObject

Shortcut for file.size.



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

def size
  @file.size
end

#to_ioObject



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

def to_io
  @file.to_io
end

#to_pathObject

Shortcut for file.to_path.



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

def to_path
  @file.to_path
end