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
-
#data_directory(relative = false) ⇒ Object
Return the directory in which the file for the current record is stored.
-
#data_path ⇒ Object
See ClassMethods.data_path.
-
#extract_filename(file_data) ⇒ Object
See ClassMethods.extract_filename.
-
#file_path(relative = false) ⇒ Object
Return the full file path for this record.
-
#full_filename ⇒ Object
Cached version of #file_path.
-
#static_path ⇒ Object
Gets the path that will be used for serving the image as a static resource.
-
#tempfile_path ⇒ Object
See ClassMethods.tempfile_path.
Instance Method Details
#data_directory(relative = false) ⇒ Object
Return the directory in which the file for the current record is stored. If the relative flag is set, it will only return the relative path inside the main data directory.
The paths will look something like: .../XmlData/031/
56 57 58 59 60 61 62 63 |
# File 'lib/talia_core/data_types/path_helpers.rb', line 56 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_path ⇒ Object
See ClassMethods.data_path
66 67 68 |
# File 'lib/talia_core/data_types/path_helpers.rb', line 66 def data_path self.class.data_path end |
#extract_filename(file_data) ⇒ Object
See ClassMethods.extract_filename
76 77 78 |
# File 'lib/talia_core/data_types/path_helpers.rb', line 76 def extract_filename(file_data) self.class.extract_filename(file_data) end |
#file_path(relative = false) ⇒ Object
Return the full file path for this record. If the relative flag is set, this will only return the relative path inside the data directory
24 25 26 |
# File 'lib/talia_core/data_types/path_helpers.rb', line 24 def file_path(relative = false) File.join(data_directory(relative), self.id.to_s) end |
#full_filename ⇒ Object
Cached version of #file_path
71 72 73 |
# File 'lib/talia_core/data_types/path_helpers.rb', line 71 def full_filename @full_filename ||= self.file_path #File.join(data_path, class_name, location) end |
#static_path ⇒ Object
Gets the path that will be used for serving the image as a static resource.
This will return nil unless the static_data_prefix
option is set in the configuration. This option defines a URL prefix for static files.
If the prefix is set, this method will return a URL that can be used access the current file as a static asset. To use this, the data directory has to be available on a web server at the static_data_prefix
39 40 41 42 43 44 |
# File 'lib/talia_core/data_types/path_helpers.rb', line 39 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_path ⇒ Object
See ClassMethods.tempfile_path
47 48 49 |
# File 'lib/talia_core/data_types/path_helpers.rb', line 47 def tempfile_path self.class.tempfile_path end |