data_file.rb 372 B

12345678910111213141516171819
  1. class DataFile < ApplicationRecord
  2. require 'fileutils'
  3. before_destroy :delete_file
  4. belongs_to :repository, polymorphic: true
  5. def dir_path
  6. Rails.root.join('public', 'uploads', self.uuid)
  7. end
  8. def file_path
  9. Rails.root.join('public', 'uploads', self.uuid, self.name)
  10. end
  11. private
  12. def delete_file
  13. FileUtils.rm_rf(self.dir_path)
  14. end
  15. end