Class: Balloon::Storage::File

Inherits:
Store
  • Object
show all
Defined in:
lib/balloon/storage/file.rb

Instance Method Summary collapse

Methods inherited from Store

basic_auth, conn_option, #connection, get_basic_auth, get_option, #initialize, #set_upload_name, #store_name, token_auth, #upload_dir, #upload_file

Constructor Details

This class inherits a constructor from Balloon::Storage::Store

Instance Method Details

#delete!Object



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/balloon/storage/file.rb', line 51

def delete!
  return false if !upload_file
  path = ::File.join store_path, store_filename
  FileUtils.rm(path) if ::File.exist?(path)
  if @uploader.respond_to?(:uploader_size)
    @uploader.uploader_size.each do |s, o|
      path = ::File.join store_path, store_filename(s)
      FileUtils.rm(path) if ::File.exist?(path)
    end
  end
end

#local_path!(size_name = nil) ⇒ Object



40
41
42
43
# File 'lib/balloon/storage/file.rb', line 40

def local_path!(size_name = nil)
  path = ::File.join @uploader.store_dir, path!(size_name)
  return ::File.expand_path(::File.join(@uploader.root, path))
end

#path!(size_name = nil) ⇒ Object



34
35
36
37
38
# File 'lib/balloon/storage/file.rb', line 34

def path!(size_name = nil)
  return "" if !upload_file
  path = ::File.join upload_dir, store_filename(size_name)
  return "/#{path}"
end

#retrieve!(size_name = nil) ⇒ Object



45
46
47
48
49
# File 'lib/balloon/storage/file.rb', line 45

def retrieve!(size_name = nil)
  path = path!(size_name)
  return path if @uploader.asset_host.nil?
  return "#{@uploader.asset_host}#{path}"
end

#store!Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/balloon/storage/file.rb', line 4

def store!
  _store_path = store_path
  cache_meta = @uploader.cache_meta

  if !::File.exist? _store_path
    FileUtils.mkdir_p _store_path
    FileUtils.chmod_R @uploader.dir_permissions.to_i,  _store_path
  end

  original_file = set_upload_name

  store_original_file = ::File.join _store_path, original_file
  cache_original_file = ::File.join @uploader.cache_path, cache_meta[:filename]

  FileUtils.mv cache_original_file, store_original_file

  if @uploader.respond_to?(:uploader_size)
    @uploader.uploader_size.each do |s, o|
      store_file = ::File.join _store_path, set_upload_name(s)
      cache_file = ::File.join @uploader.cache_path, cache_meta[:basename]+ "_#{s}"+"."+ cache_meta[:extension]
      FileUtils.mv cache_file, store_file
    end
  end

  # Remove cache path
  FileUtils.remove_dir(@uploader.cache_path)

  return { filename: original_file, basename: store_name}
end