module MiGA::Common::WithResult

Helper module including specific functions to handle objects that have results.

Public Instance Methods

add_result(task, save = true, opts = {}) click to toggle source

Look for the result with symbol key task and register it in the object. If save is false, it doesn't register the result, but it still returns a result if it already exists.

The opts hash controls result creation (if necessary). Supported values include:

  • is_clean: A Boolean indicating if the input files are clean

  • force: A Boolean indicating if the result must be re-indexed, ignored unless +save = true+

Returns MiGA::Result or nil

# File lib/miga/common/with_result.rb, line 23
def add_result(task, save = true, opts = {})
  task = task.to_sym
  return nil if result_dirs[task].nil?

  base = File.join(
    project.path, "data/#{result_dirs[task]}/#{result_base}"
  json = "#{base}.json"
  return MiGA::Result.load(json) unless save

  MiGA::Result.create(json, opts[:force]) do
    r = send("add_result_#{task}", base, opts) if File.exist?("#{base}.done")
    unless r.nil?
      pull_hook(:on_result_ready, r.key)
each_result() { |key, res| ... } click to toggle source

For each result execute the 2-ary block: key symbol and MiGA::Result

# File lib/miga/common/with_result.rb, line 61
def each_result
  results.each { |res| yield(res.key, res) }
get_result(task) click to toggle source

Get a result as MiGA::Result for the object with key task. This is equivalent to +add_result(task, false)+.

# File lib/miga/common/with_result.rb, line 68
def get_result(task)
  add_result(task, false)
result(task) click to toggle source

Get the result MiGA::Result in this object identified by the symbol task

# File lib/miga/common/with_result.rb, line 44
def result(task)
  task = task.to_sym
  return nil if result_dirs[task].nil?

result_dirs() click to toggle source

Result directories as a Hash

# File lib/miga/common/with_result.rb, line 7
def result_dirs
results() click to toggle source

Get all the results (Array of MiGA::Result) in this object

# File lib/miga/common/with_result.rb, line 55
def results { |k| result k }.compact