Class: Refile::File
- Inherits:
-
Object
- Object
- Refile::File
- Defined in:
- lib/refile/file.rb
Instance Attribute Summary collapse
-
#backend ⇒ Backend
readonly
The backend the file is stored in.
-
#id ⇒ String
readonly
The id of the file.
Instance Method Summary collapse
-
#close
Close the file object and release its file descriptor.
-
#delete
Remove the file from the backend.
-
#download ⇒ Tempfile
Downloads the file to a Tempfile on disk and returns this tempfile.
-
#eof? ⇒ Boolean
Returns whether there is more data to read.
-
#exists? ⇒ Boolean
Whether the file exists in the backend.
-
#read(*args) ⇒ String
Reads from the file.
-
#size ⇒ Integer
The size of the file in bytes.
-
#to_io ⇒ IO
An IO object which contains the contents of the file.
Instance Attribute Details
#backend ⇒ Backend (readonly)
Returns the backend the file is stored in.
4 5 6 |
# File 'lib/refile/file.rb', line 4 def backend @backend end |
#id ⇒ String (readonly)
Returns the id of the file.
7 8 9 |
# File 'lib/refile/file.rb', line 7 def id @id end |
Instance Method Details
#close
This method returns an undefined value.
Close the file object and release its file descriptor.
35 36 37 |
# File 'lib/refile/file.rb', line 35 def close io.close end |
#delete
This method returns an undefined value.
Remove the file from the backend.
47 48 49 |
# File 'lib/refile/file.rb', line 47 def delete backend.delete(id) end |
#download ⇒ Tempfile
Downloads the file to a Tempfile on disk and returns this tempfile.
69 70 71 72 73 74 75 |
# File 'lib/refile/file.rb', line 69 def download return io if io.is_a?(Tempfile) Tempfile.new(id, binmode: true).tap do |tempfile| IO.copy_stream(io, tempfile) end end |
#eof? ⇒ Boolean
Returns whether there is more data to read. Returns true if the end of the data has been reached.
28 29 30 |
# File 'lib/refile/file.rb', line 28 def eof? io.eof? end |
#exists? ⇒ Boolean
Returns whether the file exists in the backend.
52 53 54 |
# File 'lib/refile/file.rb', line 52 def exists? backend.exists?(id) end |
#read(*args) ⇒ String
Reads from the file.
20 21 22 |
# File 'lib/refile/file.rb', line 20 def read(*args) io.read(*args) end |
#size ⇒ Integer
Returns the size of the file in bytes.
40 41 42 |
# File 'lib/refile/file.rb', line 40 def size backend.size(id) end |
#to_io ⇒ IO
Returns an IO object which contains the contents of the file.
57 58 59 |
# File 'lib/refile/file.rb', line 57 def to_io io end |