Sha256: e3c9606adfe97b88bb923f419b9271d17ae6b93483e239909aeeb94d085a8c44

Contents?: true

Size: 1.84 KB

Versions: 276

Compression:

Stored size: 1.84 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 self.load_inputs(dir, input_names, input_types)
    inputs = {}
    dir = Path.setup(dir.dup)
    input_names.each do |input|
      file = dir[input].find
      Log.debug "Trying #{ input }: #{file}"
      next unless file.exists?

      case input_types[input]
      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
    IndiferentHash.setup(inputs)
  end

  def example_step(task_name, example)
    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
    self.job(task_name, example, inputs)
  end
end

Version data entries

276 entries across 276 versions & 1 rubygems

Version Path
rbbt-util-5.21.63 lib/rbbt/workflow/examples.rb
rbbt-util-5.21.62 lib/rbbt/workflow/examples.rb
rbbt-util-5.21.61 lib/rbbt/workflow/examples.rb
rbbt-util-5.21.60 lib/rbbt/workflow/examples.rb
rbbt-util-5.21.59 lib/rbbt/workflow/examples.rb
rbbt-util-5.21.58 lib/rbbt/workflow/examples.rb
rbbt-util-5.21.57 lib/rbbt/workflow/examples.rb
rbbt-util-5.21.56 lib/rbbt/workflow/examples.rb
rbbt-util-5.21.55 lib/rbbt/workflow/examples.rb
rbbt-util-5.21.54 lib/rbbt/workflow/examples.rb
rbbt-util-5.21.53 lib/rbbt/workflow/examples.rb
rbbt-util-5.21.51 lib/rbbt/workflow/examples.rb
rbbt-util-5.21.50 lib/rbbt/workflow/examples.rb
rbbt-util-5.21.49 lib/rbbt/workflow/examples.rb
rbbt-util-5.21.47 lib/rbbt/workflow/examples.rb
rbbt-util-5.21.46 lib/rbbt/workflow/examples.rb
rbbt-util-5.21.45 lib/rbbt/workflow/examples.rb
rbbt-util-5.21.44 lib/rbbt/workflow/examples.rb
rbbt-util-5.21.43 lib/rbbt/workflow/examples.rb
rbbt-util-5.21.42 lib/rbbt/workflow/examples.rb