Sha256: 4ecd4ea5d2ac7379aac4b8b09f9f153a0334c4b6cd841c8c6ca7f817e99a2440

Contents?: true

Size: 967 Bytes

Versions: 55

Compression:

Stored size: 967 Bytes

Contents

require "tempfile"

module Rack
  module Test

    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)
        @tempfile.set_encoding(Encoding::BINARY) if @tempfile.respond_to?(:set_encoding)
        @tempfile.binmode if binary
        FileUtils.copy_file(path, @tempfile.path)
      end

      def path
        @tempfile.path
      end

      alias_method :local_path, :path

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

    end

  end
end

Version data entries

55 entries across 55 versions & 4 rubygems

Version Path
josh-rack-test-0.4.1 lib/rack/test/uploaded_file.rb
josh-rack-test-0.4.2 lib/rack/test/uploaded_file.rb
tdreyno-middleman-0.2.4 vendor/rack-test/lib/rack/test/uploaded_file.rb
tdreyno-middleman-0.2.5 vendor/rack-test/lib/rack/test/uploaded_file.rb
tdreyno-middleman-0.2.6 vendor/rack-test/lib/rack/test/uploaded_file.rb
tdreyno-middleman-0.2.7 vendor/rack-test/lib/rack/test/uploaded_file.rb
tdreyno-middleman-0.2.8 vendor/rack-test/lib/rack/test/uploaded_file.rb
tdreyno-middleman-0.2.9 vendor/rack-test/lib/rack/test/uploaded_file.rb
tdreyno-middleman-0.3.0 vendor/rack-test/lib/rack/test/uploaded_file.rb
tdreyno-middleman-0.3.1 vendor/rack-test/lib/rack/test/uploaded_file.rb
tdreyno-middleman-0.3.10 vendor/rack-test/lib/rack/test/uploaded_file.rb
tdreyno-middleman-0.3.2 vendor/rack-test/lib/rack/test/uploaded_file.rb
tdreyno-middleman-0.3.3 vendor/rack-test/lib/rack/test/uploaded_file.rb
tdreyno-middleman-0.3.4 vendor/rack-test/lib/rack/test/uploaded_file.rb
tdreyno-middleman-0.3.7 vendor/rack-test/lib/rack/test/uploaded_file.rb
tdreyno-middleman-0.3.8 vendor/rack-test/lib/rack/test/uploaded_file.rb
tdreyno-middleman-0.4.1 vendor/rack-test/lib/rack/test/uploaded_file.rb
tdreyno-middleman-0.5.0 vendor/rack-test/lib/rack/test/uploaded_file.rb
tdreyno-middleman-0.5.2 vendor/rack-test/lib/rack/test/uploaded_file.rb
tdreyno-middleman-0.5.3 vendor/rack-test/lib/rack/test/uploaded_file.rb