Module: Task

Defined in:
lib/rbbt/workflow/task.rb,
lib/rbbt/workflow/usage.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



5
6
7
# File 'lib/rbbt/workflow/task.rb', line 5

def description
  @description
end

#extensionObject

Returns the value of attribute extension.



5
6
7
# File 'lib/rbbt/workflow/task.rb', line 5

def extension
  @extension
end

#input_defaultsObject

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_descriptionsObject

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_optionsObject

Returns the value of attribute input_options.



5
6
7
# File 'lib/rbbt/workflow/task.rb', line 5

def input_options
  @input_options
end

#input_typesObject

Returns the value of attribute input_types.



5
6
7
# File 'lib/rbbt/workflow/task.rb', line 5

def input_types
  @input_types
end

#inputsObject

Returns the value of attribute inputs.



5
6
7
# File 'lib/rbbt/workflow/task.rb', line 5

def inputs
  @inputs
end

#nameObject

Returns the value of attribute name.



5
6
7
# File 'lib/rbbt/workflow/task.rb', line 5

def name
  @name
end

#result_descriptionObject

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_typeObject

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
88
# 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 : []
    raise "Dependency task not found: #{dep}" if task.nil?
    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(options = {}, &block)
  block.extend Task
  options = IndiferentHash.setup options
  block.singleton_methods.
    select{|method| method.to_s[-1] != "="[0]}.each{|method|
    if block.respond_to?(method.to_s + "=") and options.include? method.to_sym
      block.send(method.to_s + '=', options[method.to_sym]) 
    end
  }
  block
end

Instance Method Details

#dep_inputs(deps, workflow = nil) ⇒ Object



90
91
92
93
94
95
# File 'lib/rbbt/workflow/task.rb', line 90

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_descriptionObject



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