def initialize(obj, name=nil)
if obj.is_a? TempObject
@data = obj.get_data
@tempfile = obj.get_tempfile
@pathname = obj.get_pathname
elsif obj.is_a? String
@data = obj
elsif obj.is_a? Tempfile
@tempfile = obj
elsif obj.is_a? File
@pathname = Pathname.new(obj.path)
elsif obj.is_a? Pathname
@pathname = obj
elsif obj.respond_to?(:tempfile)
@tempfile = obj.tempfile
elsif obj.respond_to?(:path)
@pathname = Pathname.new(obj.path)
else
raise ArgumentError, "#{self.class.name} must be initialized with a String, a Pathname, a File, a Tempfile, another TempObject, something that responds to .tempfile, or something that responds to .path - you gave #{obj.inspect}"
end
@tempfile.close if @tempfile
@name = if name
name
elsif obj.respond_to?(:original_filename)
obj.original_filename
elsif @pathname
@pathname.basename.to_s
end
end