2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/multi_part/file_upload_io.rb', line 2
def self.new(file_path, content_type, file_content = nil)
raise ArgumentError, "File content type required" unless content_type
File.open(file_path, "w+b", 0644) { |f| f.write file_content } unless file_content.blank?
file_io = File.open(file_path, "rb")
file_io.instance_eval(<<-EOS, __FILE__, __LINE__)
def content_type
"#{content_type}"
end
def file_name
"#{File.basename(file_path)}"
end
def file_size
"#{File.size(file_path)}".to_i
end
EOS
file_io
end
|