aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/http/upload.rb
diff options
context:
space:
mode:
authorCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2012-03-06 18:34:20 -0300
committerCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2012-03-06 18:34:20 -0300
commit8d5c742df4d172c084a84013009b052eeb9551a6 (patch)
treeb4a436551348be5622245337be9c0b707bfc6d85 /actionpack/lib/action_dispatch/http/upload.rb
parentd1a4faf61f64e53797d13b7c2f150b94be94e916 (diff)
downloadrails-8d5c742df4d172c084a84013009b052eeb9551a6.tar.gz
rails-8d5c742df4d172c084a84013009b052eeb9551a6.tar.bz2
rails-8d5c742df4d172c084a84013009b052eeb9551a6.zip
Refactor AD::UploadedFile, and raise sooner if tempfile is not present
Diffstat (limited to 'actionpack/lib/action_dispatch/http/upload.rb')
-rw-r--r--actionpack/lib/action_dispatch/http/upload.rb14
1 files changed, 6 insertions, 8 deletions
diff --git a/actionpack/lib/action_dispatch/http/upload.rb b/actionpack/lib/action_dispatch/http/upload.rb
index 5ab99d1061..c4a915d1ad 100644
--- a/actionpack/lib/action_dispatch/http/upload.rb
+++ b/actionpack/lib/action_dispatch/http/upload.rb
@@ -4,11 +4,12 @@ module ActionDispatch
attr_accessor :original_filename, :content_type, :tempfile, :headers
def initialize(hash)
+ @tempfile = hash[:tempfile]
+ raise(ArgumentError, ':tempfile is required') unless @tempfile
+
@original_filename = encode_filename(hash[:filename])
@content_type = hash[:type]
@headers = hash[:head]
- @tempfile = hash[:tempfile]
- raise(ArgumentError, ':tempfile is required') unless @tempfile
end
def read(*args)
@@ -19,15 +20,12 @@ module ActionDispatch
[:open, :path, :rewind, :size].each do |method|
class_eval "def #{method}; @tempfile.#{method}; end"
end
-
+
private
+
def encode_filename(filename)
# Encode the filename in the utf8 encoding, unless it is nil
- if filename
- filename.force_encoding("UTF-8").encode!
- else
- filename
- end
+ filename.force_encoding("UTF-8").encode! if filename
end
end