Module: Task
- Defined in:
- lib/rbbt/workflow/task.rb,
lib/rbbt/workflow/usage.rb
Instance Attribute Summary collapse
-
#description ⇒ Object
Returns the value of attribute description.
-
#extension ⇒ Object
Returns the value of attribute extension.
-
#input_defaults ⇒ Object
Returns the value of attribute input_defaults.
-
#input_descriptions ⇒ Object
Returns the value of attribute input_descriptions.
-
#input_options ⇒ Object
Returns the value of attribute input_options.
-
#input_types ⇒ Object
Returns the value of attribute input_types.
-
#inputs ⇒ Object
Returns the value of attribute inputs.
-
#name ⇒ Object
Returns the value of attribute name.
-
#result_description ⇒ Object
Returns the value of attribute result_description.
-
#result_type ⇒ Object
Returns the value of attribute result_type.
Class Method Summary collapse
Instance Method Summary collapse
- #dep_inputs(deps, workflow = nil) ⇒ Object
- #doc(workflow = nil, deps = nil) ⇒ Object
- #exec(*args) ⇒ Object
- #exec_in(object, *args) ⇒ Object
- #parse_description ⇒ Object
- #persist_exec(filename, *args) ⇒ Object
- #persist_exec_in(filename, *args) ⇒ Object
- #take_input_values(input_values) ⇒ Object
Instance Attribute Details
#description ⇒ Object
Returns the value of attribute description.
5 6 7 |
# File 'lib/rbbt/workflow/task.rb', line 5 def description @description end |
#extension ⇒ Object
Returns the value of attribute extension.
5 6 7 |
# File 'lib/rbbt/workflow/task.rb', line 5 def extension @extension end |
#input_defaults ⇒ Object
Returns the value of attribute input_defaults.
5 6 7 |
# File 'lib/rbbt/workflow/task.rb', line 5 def input_defaults @input_defaults end |
#input_descriptions ⇒ Object
Returns the value of attribute input_descriptions.
5 6 7 |
# File 'lib/rbbt/workflow/task.rb', line 5 def input_descriptions @input_descriptions end |
#input_options ⇒ Object
Returns the value of attribute input_options.
5 6 7 |
# File 'lib/rbbt/workflow/task.rb', line 5 def @input_options end |
#input_types ⇒ Object
Returns the value of attribute input_types.
5 6 7 |
# File 'lib/rbbt/workflow/task.rb', line 5 def input_types @input_types end |
#inputs ⇒ Object
Returns the value of attribute inputs.
5 6 7 |
# File 'lib/rbbt/workflow/task.rb', line 5 def inputs @inputs end |
#name ⇒ Object
Returns the value of attribute name.
5 6 7 |
# File 'lib/rbbt/workflow/task.rb', line 5 def name @name end |
#result_description ⇒ Object
Returns the value of attribute result_description.
5 6 7 |
# File 'lib/rbbt/workflow/task.rb', line 5 def result_description @result_description end |
#result_type ⇒ Object
Returns the value of attribute result_type.
5 6 7 |
# File 'lib/rbbt/workflow/task.rb', line 5 def result_type @result_type end |
Class Method Details
.dep_inputs(deps, workflow = nil) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/rbbt/workflow/task.rb', line 74 def self.dep_inputs(deps, workflow = nil) seen = [] task_inputs = {} deps.each do |dep| wf, task = (Array === dep ? [dep.first, dep.first.tasks[dep[1].to_sym]] : [workflow, workflow.tasks[dep.to_sym]]) maps = (Array === dep and Hash === dep.last) ? dep.last.keys : [] next if seen.include? [wf, task.name] seen << [wf, task.name] new_inputs = task.inputs - maps next unless new_inputs.any? task_inputs[task] = new_inputs end task_inputs end |
.setup(options = {}, &block) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/rbbt/workflow/task.rb', line 7 def self.setup( = {}, &block) block.extend Task = IndiferentHash.setup block.singleton_methods. select{|method| method.to_s[-1] != "="[0]}.each{|method| if block.respond_to?(method.to_s + "=") and .include? method.to_sym block.send(method.to_s + '=', [method.to_sym]) end } block end |
Instance Method Details
#dep_inputs(deps, workflow = nil) ⇒ Object
89 90 91 92 93 94 |
# File 'lib/rbbt/workflow/task.rb', line 89 def dep_inputs(deps, workflow = nil) task_inputs = Task.dep_inputs deps, workflow task_inputs.each do |task, inputs| inputs.replace (inputs - self.inputs) end end |
#doc(workflow = nil, deps = nil) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/rbbt/workflow/usage.rb', line 4 def doc(workflow = nil, deps = nil) puts Log.color(:yellow, "## #{ name }") << ":" puts "\n" << description << "\n" if description and not description.empty? puts case when (input_types.values & [:array]).any? puts Log.color(:green, Misc.format_paragraph("Lists are specified as arguments using ',' or '|'. When specified as files the '\\n' also works in addition to the others. You may use the '--array_separator' option the change this default. Whenever a file is specified it may also accept STDIN using the '-' character.")) puts when (input_types.values & [:text, :tsv]).any? puts Log.color(:green, Misc.format_paragraph("Whenever a file is specified it may also accept STDIN using the '-' character.")) puts end if inputs.any? puts SOPT.input_doc(inputs, input_types, input_descriptions, input_defaults, true) puts end if deps and deps.any? puts Log.color(:magenta, "Inputs from dependencies:") puts seen = [] task_inputs = dep_inputs deps, workflow task_inputs.each do |task,new_inputs| puts " #{Log.color :yellow, task.name.to_s}:" puts puts SOPT.input_doc(new_inputs, task.input_types, task.input_descriptions, task.input_defaults, true) puts end end puts Log.color(:magenta, "Returns: ") << Log.color(:blue, result_type.to_s) << "\n" puts end |
#exec(*args) ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/rbbt/workflow/task.rb', line 44 def exec(*args) case when (args.length == 1 and not inputs.nil? and inputs.length > 1 and Hash === args.first) self.call *take_input_values(IndiferentHash.setup(args.first)) else self.call *args end end |
#exec_in(object, *args) ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/rbbt/workflow/task.rb', line 53 def exec_in(object, *args) case when (args.length == 1 and not inputs.nil? and inputs.length > 1 and Hash === args.first) object.instance_exec *IndiferentHash.setup(args.first).values_at(*inputs), &self else object.instance_exec *args, &self end end |
#parse_description ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/rbbt/workflow/task.rb', line 19 def parse_description if description =~ /\n\n/ short_description, rest = description.match(/(.*?)\n\n(.*)/).values_at 1, 2 else short_description = description rest = nil end if rest.nil? long_description = "" end end |
#persist_exec(filename, *args) ⇒ Object
62 63 64 65 66 |
# File 'lib/rbbt/workflow/task.rb', line 62 def persist_exec(filename, *args) Persist.persist "Task", @persistence_type, :file => filename do exec *args end end |
#persist_exec_in(filename, *args) ⇒ Object
68 69 70 71 72 |
# File 'lib/rbbt/workflow/task.rb', line 68 def persist_exec_in(filename, *args) Persist.persist "Task", @persistence_type, :file => filename do exec_in *args end end |
#take_input_values(input_values) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/rbbt/workflow/task.rb', line 32 def take_input_values(input_values) return [] if @inputs.nil? values = [] defaults = IndiferentHash.setup(@input_defaults || {}) @inputs.each do |input| value = input_values[input] value = defaults[input] if value.nil? values << value end values end |