/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

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