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
Fileobject with the actual uploaded file. -
#original_filename ⇒ Object
readonly
The basename of the file in the client.
Instance Method Summary collapse
-
#close ⇒ Object
Shortcut for
file.close. -
#eof? ⇒ Boolean
Shortcut for
file.eof?. -
#initialize(file, original_filename, content_type) ⇒ UploadedFile
constructor
A new instance of UploadedFile.
-
#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.
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_type ⇒ Object (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 |
#file ⇒ Object (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_filename ⇒ Object (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
#close ⇒ Object
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?.
59 60 61 |
# File 'lib/rage/uploaded_file.rb', line 59 def eof? @file.eof? end |
#path ⇒ Object
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 |
#rewind ⇒ Object
Shortcut for file.rewind.
49 50 51 |
# File 'lib/rage/uploaded_file.rb', line 49 def rewind @file.rewind end |
#size ⇒ Object
Shortcut for file.size.
54 55 56 |
# File 'lib/rage/uploaded_file.rb', line 54 def size @file.size end |
#to_io ⇒ Object
63 64 65 |
# File 'lib/rage/uploaded_file.rb', line 63 def to_io @file.to_io end |
#to_path ⇒ Object
Shortcut for file.to_path.
44 45 46 |
# File 'lib/rage/uploaded_file.rb', line 44 def to_path @file.to_path end |