Module: TaliaCore::DataTypes::PathHelpers

Included in:
FileRecord
Defined in:
lib/talia_core/data_types/path_helpers.rb

Overview

Contains the helpers to obtain path information for data storage

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#data_directory(relative = false) ⇒ Object

Return the data directory for a specific data file



48
49
50
51
52
53
54
55
# File 'lib/talia_core/data_types/path_helpers.rb', line 48

def data_directory(relative = false)
  class_name = self.class.name.gsub(/(.*::)/, '')
  if relative == false
    File.join(TaliaCore::CONFIG["data_directory_location"], class_name, ("00" + self.id.to_s)[-3..-1])
  else
    File.join(class_name, ("00" + self.id.to_s)[-3..-1])
  end
end

#data_pathObject

Path used to store data files. This is a wrapper for the data_path class method.



59
60
61
# File 'lib/talia_core/data_types/path_helpers.rb', line 59

def data_path
  self.class.data_path
end

#extract_filename(file_data) ⇒ Object

Extract the filename. This is a wrapper for the extract_filename class method.



70
71
72
# File 'lib/talia_core/data_types/path_helpers.rb', line 70

def extract_filename(file_data)
  self.class.extract_filename(file_data)
end

#file_path(relative = false) ⇒ Object

Return the full file path related to the data directory



28
29
30
# File 'lib/talia_core/data_types/path_helpers.rb', line 28

def file_path(relative = false)
  File.join(data_directory(relative), self.id.to_s)
end

#full_filenameObject

Return the full path of the current attachment.



64
65
66
# File 'lib/talia_core/data_types/path_helpers.rb', line 64

def full_filename
  @full_filename ||= self.file_path #File.join(data_path, class_name, location)
end

#static_pathObject

Gets the path that will be used for serving the image as a static resource. Nil if the prefix isn’t set



34
35
36
37
38
39
# File 'lib/talia_core/data_types/path_helpers.rb', line 34

def static_path
  prefix = TaliaCore::CONFIG['static_data_prefix']
  return unless(prefix)
  prefix = N::LOCAL + prefix unless(prefix =~ /:\/\//)
  "#{prefix}/#{class_name}/#{("00" + self.id.to_s)[-3..-1]}/#{self.id}"
end

#tempfile_pathObject

Path used to store temporary files. This is a wrapper for the tempfile_path class method.



43
44
45
# File 'lib/talia_core/data_types/path_helpers.rb', line 43

def tempfile_path
  self.class.tempfile_path
end