debian-mirror-gitlab/lib/uploaded_file.rb

37 lines
954 B
Ruby
Raw Normal View History

2015-11-26 14:37:03 +05:30
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:
2018-03-17 18:26:18 +05:30
@tempfile.__send__(method_name, *args, &block) # rubocop:disable GitlabSecurity/PublicSend
2015-11-26 14:37:03 +05:30
end
def respond_to?(method_name, include_private = false) #:nodoc:
@tempfile.respond_to?(method_name, include_private) || super
end
end