PageRenderTime 27ms CodeModel.GetById 9ms app.highlight 14ms RepoModel.GetById 2ms app.codeStats 0ms

/vendor/bundle/jruby/2.1/gems/rack-1.5.2/lib/rack/multipart/uploaded_file.rb

https://github.com/delowong/logstash
Ruby | 34 lines | 27 code | 5 blank | 2 comment | 2 complexity | 06aa1987cdddb3f484ecea2faba49bf6 MD5 | raw file
 1module Rack
 2  module Multipart
 3    class UploadedFile
 4      # The filename, *not* including the path, of the "uploaded" file
 5      attr_reader :original_filename
 6
 7      # The content type of the "uploaded" file
 8      attr_accessor :content_type
 9
10      def initialize(path, content_type = "text/plain", binary = false)
11        raise "#{path} file does not exist" unless ::File.exist?(path)
12        @content_type = content_type
13        @original_filename = ::File.basename(path)
14        @tempfile = Tempfile.new(@original_filename)
15        @tempfile.set_encoding(Encoding::BINARY) if @tempfile.respond_to?(:set_encoding)
16        @tempfile.binmode if binary
17        FileUtils.copy_file(path, @tempfile.path)
18      end
19
20      def path
21        @tempfile.path
22      end
23      alias_method :local_path, :path
24
25      def respond_to?(*args)
26        super or @tempfile.respond_to?(*args)
27      end
28
29      def method_missing(method_name, *args, &block) #:nodoc:
30        @tempfile.__send__(method_name, *args, &block)
31      end
32    end
33  end
34end