class Incline::WorkPath
This class simply locates a temporary working directory for the application.
By default we shoot for shared memory such as /run/shm or /dev/shm. If those fail, we look to /tmp.
Public Class Methods
location()
click to toggle source
Gets the temporary working directory location for the application.
# File lib/incline/work_path.rb, line 13 def self.location @location ||= get_location end
path_for(filename)
click to toggle source
Gets a path for a specific temporary file.
# File lib/incline/work_path.rb, line 20 def self.path_for(filename) location + '/' + filename end
system_status_file()
click to toggle source
Gets the path to the system status file.
This file is used by long running processes to log their progress.
# File lib/incline/work_path.rb, line 29 def self.system_status_file @system_status_file ||= path_for('system_status') end
Private Class Methods
app_name()
click to toggle source
# File lib/incline/work_path.rb, line 35 def self.app_name @app_name ||= Rails.application.class.name.underscore.gsub('/','_') end
get_location()
click to toggle source
# File lib/incline/work_path.rb, line 64 def self.get_location (%w(/run/shm /var/run/shm /dev/shm /tmp) + [Dir.tmpdir]).each do |root| if Dir.exist?(root) loc = try_path(root) return loc unless loc.blank? end end nil end
try_path(path)
click to toggle source
# File lib/incline/work_path.rb, line 39 def self.try_path(path) path += '/incline_' + app_name Incline::Log::debug "Trying path '#{path}'..." # must exist or be able to be created. unless Dir.exist?(path) || Dir.mkdir(path) Incline::Log::debug 'Could not create path.' return nil end # must be able to write and delete a test file. test_file = path + '/test.file' begin File.delete(test_file) if File.exist?(test_file) File.write(test_file, 'This is only a test file and can safely be deleted.') File.delete(test_file) rescue Incline::Log::debug 'Could not create test file.' path = nil end path end