Module: Gluttonberg::Library::Storage::Filesystem

Extended by:
ActiveSupport::Concern
Defined in:
lib/gluttonberg/library/storage/filesystem.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#assets_directory_public_urlObject



30
31
32
# File 'lib/gluttonberg/library/storage/filesystem.rb', line 30

def assets_directory_public_url
  "/user_assets"
end

#directoryObject

The generated directory where this file is located. If it is an image it’s thumbnails will be stored here as well.



20
21
22
23
# File 'lib/gluttonberg/library/storage/filesystem.rb', line 20

def directory
  self.class.storage_setup if Library.root.blank?
  Library.root + "/" + self.asset_hash
end

#download_asset_to_tmp_fileObject



50
51
52
# File 'lib/gluttonberg/library/storage/filesystem.rb', line 50

def download_asset_to_tmp_file
  # just dummy method. As we don't need to download file for filesystem storage
end

#make_backup(replace_backup = true) ⇒ Object



34
35
36
37
38
# File 'lib/gluttonberg/library/storage/filesystem.rb', line 34

def make_backup(replace_backup=true)
  FileUtils.rm(original_file_on_disk) if replace_backup && File.exist?(original_file_on_disk)
  FileUtils.cp location_on_disk, original_file_on_disk unless File.exist?(original_file_on_disk)
  FileUtils.chmod(0755,original_file_on_disk)
end

#move_tmp_file_to_actual_directory(file_name, tmp_file_dirty = true) ⇒ Object



66
67
68
69
70
# File 'lib/gluttonberg/library/storage/filesystem.rb', line 66

def move_tmp_file_to_actual_directory(file_name , tmp_file_dirty=true)
  if self.file_dirty == true
    self.file_dirty = false
  end
end

#remove_file_from_storageObject



40
41
42
43
44
# File 'lib/gluttonberg/library/storage/filesystem.rb', line 40

def remove_file_from_storage
  if File.exists?(directory)
    FileUtils.rm_r(directory)
  end
end

#remove_file_from_tmp_storageObject



46
47
48
# File 'lib/gluttonberg/library/storage/filesystem.rb', line 46

def remove_file_from_tmp_storage
  # just dummy method. As we don't need to remove because tmp and actual folder is same for filesystem
end

#tmp_directoryObject



25
26
27
28
# File 'lib/gluttonberg/library/storage/filesystem.rb', line 25

def tmp_directory
  self.class.storage_setup if Library.tmp_root.blank?
  Library.tmp_root + "/" + self.asset_hash
end

#update_file_on_storageObject



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/gluttonberg/library/storage/filesystem.rb', line 54

def update_file_on_storage
  if file
    FileUtils.mkdir(directory) unless File.exists?(directory)
    FileUtils.rm(location_on_disk) if File.exists?(location_on_disk)
    FileUtils.cp file.tempfile.path, location_on_disk
    FileUtils.chmod(0755, location_on_disk)

    #  new file has been upload, if its image generate thumbnails, if mp3 collect sound info.
    asset_processing
  end
end