BigW Consortium Gitlab

uploaded_file.rb 954 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
require "tempfile"
require "fileutils"

# Taken from: Rack::Test::UploadedFile
class UploadedFile
  # The filename, *not* including the path, of the "uploaded" file
  attr_reader :original_filename

  # The tempfile
  attr_reader :tempfile

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

  def initialize(path, filename, content_type = "text/plain")
    raise "#{path} file does not exist" unless ::File.exist?(path)

    @content_type = content_type
    @original_filename = filename || ::File.basename(path)
    @tempfile = File.new(path, 'rb')
  end

  def path
    @tempfile.path
  end

  alias_method :local_path, :path

  def method_missing(method_name, *args, &block) #:nodoc:
30
    @tempfile.__send__(method_name, *args, &block) # rubocop:disable GitlabSecurity/PublicSend
31 32 33 34 35 36
  end

  def respond_to?(method_name, include_private = false) #:nodoc:
    @tempfile.respond_to?(method_name, include_private) || super
  end
end