class EchoUploads::WritableFile
Used by `EchoUploads::PrmFileWriting#echo_uploads_write_prm_file`.
Attributes
tempfile[R]
Public Class Methods
new(metadata, options)
click to toggle source
Takes an EchoUploads::File
.
# File lib/echo_uploads/writable_file.rb, line 24 def initialize(metadata, options) tmp_name = SecureRandom.hex 10 @tempfile = Tempfile.new 'echo_uploads', Rails.root.join('tmp') @metadata = metadata @options = options end
Public Instance Methods
close()
click to toggle source
# File lib/echo_uploads/writable_file.rb, line 4 def close # Using ActionDispatch::Http::UploadedFile is ugly. We use it because # EchoUploads::File#persist! expects that. In version 1 of this gem, we should # refactor. Everything should be more modular in general. uploaded_file = ActionDispatch::Http::UploadedFile.new( tempfile: @tempfile, filename: @metadata.original_filename ) ActiveRecord::Base.transaction do # Duping the EchoUploads::File and destroy the prior one. This ensure that the # old data is cleaned out if necessary. new_metadata = @metadata.dup @metadata.destroy new_metadata.file = uploaded_file new_metadata.persist! new_metadata.owner_attr, @options @tempfile.close! end end
method_missing(meth, *args)
click to toggle source
Calls superclass method
# File lib/echo_uploads/writable_file.rb, line 31 def method_missing(meth, *args) if @tempfile.respond_to? meth @tempfile.send meth, *args else super meth, *args end end