Class: Rage::UploadedFile
- Inherits:
-
Object
- Object
- Rage::UploadedFile
- 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
-
#content_type ⇒ Object
readonly
A string with the MIME type of the file.
-
#file ⇒ Object
(also: #tempfile)
readonly
A
File
object with the actual uploaded file. -
#original_filename ⇒ Object
readonly
The basename of the file in the client.
Instance Method Summary collapse
-
#close(unlink_now = false) ⇒ Object
Shortcut for
file.close
. -
#eof? ⇒ Boolean
Shortcut for
file.eof?
. -
#initialize(file, original_filename, content_type) ⇒ UploadedFile
constructor
A new instance of UploadedFile.
-
#open ⇒ Object
Shortcut for
file.open
. -
#path ⇒ Object
Shortcut for
file.path
. -
#read(length = nil, buffer = nil) ⇒ Object
Shortcut for
file.read
. -
#rewind ⇒ Object
Shortcut for
file.rewind
. -
#size ⇒ Object
Shortcut for
file.size
. - #to_io ⇒ Object
-
#to_path ⇒ Object
Shortcut for
file.to_path
.
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_type ⇒ Object (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 |
#file ⇒ Object (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_filename ⇒ Object (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?
.
63 64 65 |
# File 'lib/rage/uploaded_file.rb', line 63 def eof? @file.eof? end |
#open ⇒ Object
Shortcut for file.open
.
33 34 35 |
# File 'lib/rage/uploaded_file.rb', line 33 def open @file.open end |
#path ⇒ Object
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 |
#rewind ⇒ Object
Shortcut for file.rewind
.
53 54 55 |
# File 'lib/rage/uploaded_file.rb', line 53 def rewind @file.rewind end |
#size ⇒ Object
Shortcut for file.size
.
58 59 60 |
# File 'lib/rage/uploaded_file.rb', line 58 def size @file.size end |
#to_io ⇒ Object
67 68 69 |
# File 'lib/rage/uploaded_file.rb', line 67 def to_io @file.to_io end |
#to_path ⇒ Object
Shortcut for file.to_path
.
48 49 50 |
# File 'lib/rage/uploaded_file.rb', line 48 def to_path @file.to_path end |