Class: Refile::File

Inherits:
Object
  • Object
show all
Defined in:
lib/refile/file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#backendObject (readonly)

Returns the value of attribute backend.



3
4
5
# File 'lib/refile/file.rb', line 3

def backend
  @backend
end

#idObject (readonly)

Returns the value of attribute id.



3
4
5
# File 'lib/refile/file.rb', line 3

def id
  @id
end

Instance Method Details

#closeObject



18
19
20
# File 'lib/refile/file.rb', line 18

def close
  io.close
end

#deleteObject



26
27
28
# File 'lib/refile/file.rb', line 26

def delete
  backend.delete(id)
end

#downloadObject



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

Returns:

  • (Boolean)


14
15
16
# File 'lib/refile/file.rb', line 14

def eof?
  io.eof?
end

#exists?Boolean

Returns:

  • (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

#sizeObject



22
23
24
# File 'lib/refile/file.rb', line 22

def size
  backend.size(id)
end

#to_ioObject



34
35
36
# File 'lib/refile/file.rb', line 34

def to_io
  io
end