Class: Rack::Uploads::UploadedFile

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/uploads/uploaded_file.rb

Direct Known Subclasses

UploadedNginxFile

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, file) ⇒ UploadedFile

Returns a new instance of UploadedFile.



6
7
8
9
10
# File 'lib/rack/uploads/uploaded_file.rb', line 6

def initialize(key, file)
  @key = key
  @file = file
  @cleanup_needed = false
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args) ⇒ Object



37
38
39
40
# File 'lib/rack/uploads/uploaded_file.rb', line 37

def method_missing(meth, *args)
  return @file[meth.to_sym] if @file[meth.to_sym]
  super(meth, *args)
end

Instance Attribute Details

#file ⇒ Object (readonly)

Returns the value of attribute file.



5
6
7
# File 'lib/rack/uploads/uploaded_file.rb', line 5

def file
  @file
end

#key ⇒ Object (readonly)

Returns the value of attribute key.



5
6
7
# File 'lib/rack/uploads/uploaded_file.rb', line 5

def key
  @key
end

Instance Method Details

#[](key) ⇒ Object



33
34
35
# File 'lib/rack/uploads/uploaded_file.rb', line 33

def [](key)
  @file[key]
end

#cleanup ⇒ Object



42
43
44
# File 'lib/rack/uploads/uploaded_file.rb', line 42

def cleanup
  rm if @cleanup_needed
end

#cp(destination) ⇒ Object



21
22
23
# File 'lib/rack/uploads/uploaded_file.rb', line 21

def cp(destination)
  FileUtils.cp(temp_path, destination)
end

#mv(destination) ⇒ Object



16
17
18
19
# File 'lib/rack/uploads/uploaded_file.rb', line 16

def mv(destination)
  FileUtils.mv(temp_path, destination)
  @cleanup_needed = false
end

#rm ⇒ Object



25
26
27
# File 'lib/rack/uploads/uploaded_file.rb', line 25

def rm
  FileUtils.rm(temp_path)
end

#size ⇒ Object



29
30
31
# File 'lib/rack/uploads/uploaded_file.rb', line 29

def size
  ::File.size(temp_path)
end

#temp_path ⇒ Object



12
13
14
# File 'lib/rack/uploads/uploaded_file.rb', line 12

def temp_path
  @file[:tempfile].path
end