Sha256: dcb3d9bd21291cd6ff96610fdf9ed2e4b6a285e36dbd492b4c96c447a6c981f2

Contents?: true

Size: 1 KB

Versions: 9

Compression:

Stored size: 1 KB

Contents

# frozen_string_literal: true

module Rack
  module Multipart
    class UploadedFile
      # The filename, *not* including the path, of the "uploaded" file
      attr_reader :original_filename

      # The content type of the "uploaded" file
      attr_accessor :content_type

      def initialize(path, content_type = "text/plain", binary = false)
        raise "#{path} file does not exist" unless ::File.exist?(path)
        @content_type = content_type
        @original_filename = ::File.basename(path)
        @tempfile = Tempfile.new([@original_filename, ::File.extname(path)], encoding: Encoding::BINARY)
        @tempfile.binmode if binary
        FileUtils.copy_file(path, @tempfile.path)
      end

      def path
        @tempfile.path
      end
      alias_method :local_path, :path

      def respond_to?(*args)
        super or @tempfile.respond_to?(*args)
      end

      def method_missing(method_name, *args, &block) #:nodoc:
        @tempfile.__send__(method_name, *args, &block)
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
rack-2.1.4.4 lib/rack/multipart/uploaded_file.rb
rack-2.1.4.3 lib/rack/multipart/uploaded_file.rb
rack-2.1.4.2 lib/rack/multipart/uploaded_file.rb
rack-2.1.4.1 lib/rack/multipart/uploaded_file.rb
rack-2.1.4 lib/rack/multipart/uploaded_file.rb
rack-2.1.3 lib/rack/multipart/uploaded_file.rb
rack-2.1.2 lib/rack/multipart/uploaded_file.rb
rack-2.1.1 lib/rack/multipart/uploaded_file.rb
rack-2.1.0 lib/rack/multipart/uploaded_file.rb