Helper module including functions to access the source of results
Detect the result key assigned to this result
# File lib/miga/result/source.rb, line 19 def key @key ||= if relative_dir == 'data/90.stats' && file_path(:metadata_index) :project_stats else MiGA::Result.RESULT_DIRS.find do |k, v| "data/#{v}" == relative_dir end.first end end
Project containing the result
# File lib/miga/result/source.rb, line 44 def project @project ||= MiGA::Project.load(project_path) end
Path to the project containing the result. In most cases this should be
identical to project.path
, but this function is provided for
safety, so the path referencing is identical to that of
self.path
whenever they need to be compared.
# File lib/miga/result/source.rb, line 53 def project_path path[0..path.rindex('/data/') - 1] end
Path of the result containing the directory relative to the parent project
# File lib/miga/result/source.rb, line 32 def relative_dir @relative_dir ||= dir.sub("#{project_path}/", '') end
Path of the result's JSON definition relative to the parent project
# File lib/miga/result/source.rb, line 38 def relative_path @relative_path ||= path.sub("#{project_path}/", '') end
Load and return the source (parent object) of a result
# File lib/miga/result/source.rb, line 8 def source @source ||= if MiGA::Project.RESULT_DIRS[key] project else project.dataset(File.basename(path, '.json')) end end