Merged updates from trunk into stable branch
[feedcatcher.git] / vendor / rails / actionpack / lib / action_controller / uploaded_file.rb
1 module ActionController
2 module UploadedFile
3 def self.included(base)
4 base.class_eval do
5 attr_accessor :original_path, :content_type
6 alias_method :local_path, :path
7 end
8 end
9
10 def self.extended(object)
11 object.class_eval do
12 attr_accessor :original_path, :content_type
13 alias_method :local_path, :path
14 end
15 end
16
17 # Take the basename of the upload's original filename.
18 # This handles the full Windows paths given by Internet Explorer
19 # (and perhaps other broken user agents) without affecting
20 # those which give the lone filename.
21 # The Windows regexp is adapted from Perl's File::Basename.
22 def original_filename
23 unless defined? @original_filename
24 @original_filename =
25 unless original_path.blank?
26 if original_path =~ /^(?:.*[:\\\/])?(.*)/m
27 $1
28 else
29 File.basename original_path
30 end
31 end
32 end
33 @original_filename
34 end
35 end
36
37 class UploadedStringIO < StringIO
38 include UploadedFile
39 end
40
41 class UploadedTempfile < Tempfile
42 include UploadedFile
43 end
44 end