Sha256: 21d1807b72e71a7e4a5f3a9d878ab46399dff9897034af1a5b066542a85ae9c3

Contents?: true

Size: 1.5 KB

Versions: 61

Compression:

Stored size: 1.5 KB

Contents

module Workflow
  attr_accessor :example_dir

  def example_dir
    @example_dir ||= self.libdir.examples
  end

  def examples
    return {} unless self.libdir.examples.exists?
    examples = {}
    example_dir.glob("*/*").each do |example_dir|
      example = File.basename(example_dir)
      task_name = File.basename(File.dirname(example_dir))
      examples[task_name] ||= []
      examples[task_name] << example
    end
    IndiferentHash.setup examples
    examples
  end

  def example(task_name, example)
    task_info(task_name.to_sym)[:input_types].collect do |input,type|
      next unless example_dir[task_name][example][input].exists?
      [input, type, example_dir[task_name][example][input].find]
    end.compact
  end

  def example_inputs(task_name, example)
    inputs = {}
    IndiferentHash.setup(inputs)
    example(task_name, example).each do |input,type,file|

      case type
      when :tsv, :array, :text
        Log.debug "Pointing #{ input } to #{file}"
        inputs[input.to_sym]  = file
      when :boolean
        inputs[input.to_sym]  = (file.read.strip == 'true')
      else
        Log.debug "Loading #{ input } from #{file}"
        inputs[input.to_sym]  = file.read.strip
      end
    end
    inputs
  end


  def example_step(task_name, example, new_inputs = {})
    inputs = example_inputs(task_name, example)

    if new_inputs and new_inputs.any?
      IndiferentHash.setup(new_inputs)
      inputs = inputs.merge(new_inputs)
    end

    self.job(task_name, example, inputs)
  end
end

Version data entries

61 entries across 61 versions & 1 rubygems

Version Path
rbbt-util-5.37.8 lib/rbbt/workflow/examples.rb
rbbt-util-5.37.6 lib/rbbt/workflow/examples.rb
rbbt-util-5.37.4 lib/rbbt/workflow/examples.rb
rbbt-util-5.37.3 lib/rbbt/workflow/examples.rb
rbbt-util-5.37.1 lib/rbbt/workflow/examples.rb
rbbt-util-5.37.0 lib/rbbt/workflow/examples.rb
rbbt-util-5.36.0 lib/rbbt/workflow/examples.rb
rbbt-util-5.35.4 lib/rbbt/workflow/examples.rb
rbbt-util-5.35.3 lib/rbbt/workflow/examples.rb
rbbt-util-5.35.2 lib/rbbt/workflow/examples.rb
rbbt-util-5.35.1 lib/rbbt/workflow/examples.rb
rbbt-util-5.34.27 lib/rbbt/workflow/examples.rb
rbbt-util-5.34.26 lib/rbbt/workflow/examples.rb
rbbt-util-5.34.25 lib/rbbt/workflow/examples.rb
rbbt-util-5.34.24 lib/rbbt/workflow/examples.rb
rbbt-util-5.34.23 lib/rbbt/workflow/examples.rb
rbbt-util-5.34.22 lib/rbbt/workflow/examples.rb
rbbt-util-5.34.21 lib/rbbt/workflow/examples.rb
rbbt-util-5.34.20 lib/rbbt/workflow/examples.rb
rbbt-util-5.34.18 lib/rbbt/workflow/examples.rb