1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/actionpack/lib/action_dispatch/http/upload.rb
2010-10-04 17:08:25 -07:00

34 lines
943 B
Ruby

require 'active_support/core_ext/object/blank'
module ActionDispatch
module Http
class UploadedFile
attr_accessor :original_filename, :content_type, :tempfile, :headers
def initialize(hash)
@original_filename = hash[:filename]
@content_type = hash[:type]
@headers = hash[:head]
@tempfile = hash[:tempfile]
raise(ArgumentError, ':tempfile is required') unless @tempfile
end
def method_missing(name, *args, &block)
@tempfile.send(name, *args, &block)
end
end
module Upload
# Convert nested Hash to HashWithIndifferentAccess and replace
# file upload hash with UploadedFile objects
def normalize_parameters(value)
if Hash === value && value.has_key?(:tempfile)
UploadedFile.new(value)
else
super
end
end
private :normalize_parameters
end
end
end