Class: FileColumn::PermanentUploadedFile

Inherits:
RealUploadedFile show all
Defined in:
lib/file_column.rb

Overview

:nodoc:

Instance Attribute Summary

Attributes inherited from BaseUploadedFile

#magick_errors

Instance Method Summary collapse

Methods inherited from RealUploadedFile

#absolute_path, #relative_path

Methods inherited from BaseUploadedFile

#absolute_dir, #after_save, #assign, #create_magick_version_if_needed, #has_magick_errors?, #just_uploaded?, #on_save, #options, #relative_dir, #temp_path, #transform_with_magick

Constructor Details

#initialize(*args) ⇒ PermanentUploadedFile

Returns a new instance of PermanentUploadedFile.



347
348
349
350
351
352
353
# File 'lib/file_column.rb', line 347

def initialize(*args)
  super *args
  @dir = File.join(store_dir, relative_path_prefix)
  @filename = @instance[@attr]
  @filename = nil if @filename.empty?
			FileUtils.mkpath(File.dirname(@dir)) unless File.exists?(File.dirname(@dir))
end

Instance Method Details

#after_destroyObject



388
389
390
# File 'lib/file_column.rb', line 388

def after_destroy
  delete_files
end

#assign_temp(temp_path) ⇒ Object



380
381
382
383
384
385
386
# File 'lib/file_column.rb', line 380

def assign_temp(temp_path)
  return nil if temp_path.nil? or temp_path.empty?

  temp = clone_as TempUploadedFile
  temp.parse_temp_path(temp_path)
  temp
end

#deleteObject



373
374
375
376
377
378
# File 'lib/file_column.rb', line 373

def delete
  file = clone_as NoUploadedFile
  @instance[@attr] = ""
  file.on_save { delete_files }
  file
end

#delete_filesObject



392
393
394
# File 'lib/file_column.rb', line 392

def delete_files
  FileUtils.rm_rf @dir
end

#move_from(local_dir, just_uploaded) ⇒ Object



355
356
357
358
359
360
361
362
363
364
365
# File 'lib/file_column.rb', line 355

def move_from(local_dir, just_uploaded)
  # remove old permament dir first
  # this creates a short moment, where neither the old nor
  # the new files exist but we can't do much about this as
  # filesystems aren't transactional.
  FileUtils.rm_rf @dir

  FileUtils.mv local_dir, @dir

  @just_uploaded = just_uploaded
end

#upload(file) ⇒ Object



367
368
369
370
371
# File 'lib/file_column.rb', line 367

def upload(file)
  temp = clone_as TempUploadedFile
  temp.store_upload(file)
  temp
end