Class: N::App::RequestPart

Inherits:
Object
  • Object
show all
Defined in:
lib/n/app/request-part.rb

Overview

RequestPart

This class encapsulates a part in a multipart request. A part is typically an uploaded files.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(original_path, body, content_type = nil) ⇒ RequestPart

Returns a new instance of RequestPart.



39
40
41
42
43
44
45
# File 'lib/n/app/request-part.rb', line 39

def initialize(original_path, body, content_type = nil)
	@original_path = original_path
	@body = body
	@content_type = content_type
	# handle dos + unix separators.
	@filename = @original_path.split(/\/|\\/).last
end

Instance Attribute Details

#bodyObject

the temp filename path



34
35
36
# File 'lib/n/app/request-part.rb', line 34

def body
  @body
end

#content_typeObject

the content-type



37
38
39
# File 'lib/n/app/request-part.rb', line 37

def content_type
  @content_type
end

#filenameObject

the filename of the part



28
29
30
# File 'lib/n/app/request-part.rb', line 28

def filename
  @filename
end

#original_pathObject

the original filename path



31
32
33
# File 'lib/n/app/request-part.rb', line 31

def original_path
  @original_path
end

Instance Method Details

#save(prefix, forced_filename = nil, forced_extension = nil) ⇒ Object

gmosx: Hack fixed save for webrick!



50
51
52
53
54
55
56
# File 'lib/n/app/request-part.rb', line 50

def save(prefix, forced_filename = nil, forced_extension = nil)
	# ARGH!! local path is used for something else, FIXME!!
	::FileUtils.mkdir_p(prefix)
	save_path = "#{prefix}/#{@filename}"
	::File.open(save_path, "wb") {|f| f.write @body }
	return save_path
end