Class: Refile::File
- Inherits:
-
Object
- Object
- Refile::File
- Defined in:
- lib/refile/file.rb
Instance Attribute Summary collapse
-
#backend ⇒ Object
readonly
Returns the value of attribute backend.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Instance Method Summary collapse
- #close ⇒ Object
- #delete ⇒ Object
- #download ⇒ Object
- #eof? ⇒ Boolean
- #exists? ⇒ Boolean
-
#initialize(backend, id) ⇒ File
constructor
A new instance of File.
- #read(*args) ⇒ Object
- #size ⇒ Object
- #to_io ⇒ Object
Constructor Details
#initialize(backend, id) ⇒ File
Returns a new instance of File.
5 6 7 8 |
# File 'lib/refile/file.rb', line 5 def initialize(backend, id) @backend = backend @id = id end |
Instance Attribute Details
#backend ⇒ Object (readonly)
Returns the value of attribute backend.
3 4 5 |
# File 'lib/refile/file.rb', line 3 def backend @backend end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
3 4 5 |
# File 'lib/refile/file.rb', line 3 def id @id end |
Instance Method Details
#close ⇒ Object
18 19 20 |
# File 'lib/refile/file.rb', line 18 def close io.close end |
#delete ⇒ Object
26 27 28 |
# File 'lib/refile/file.rb', line 26 def delete backend.delete(id) end |
#download ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/refile/file.rb', line 38 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
14 15 16 |
# File 'lib/refile/file.rb', line 14 def eof? io.eof? end |
#exists? ⇒ Boolean
30 31 32 |
# File 'lib/refile/file.rb', line 30 def exists? backend.exists?(id) end |
#read(*args) ⇒ Object
10 11 12 |
# File 'lib/refile/file.rb', line 10 def read(*args) io.read(*args) end |
#size ⇒ Object
22 23 24 |
# File 'lib/refile/file.rb', line 22 def size backend.size(id) end |
#to_io ⇒ Object
34 35 36 |
# File 'lib/refile/file.rb', line 34 def to_io io end |