Class: TaskManager
- Inherits:
-
Object
- Object
- TaskManager
- Defined in:
- lib/task_manager.rb
Instance Method Summary collapse
- #add(task) ⇒ Object
-
#initialize(output) ⇒ TaskManager
constructor
A new instance of TaskManager.
- #output_exception(ex) ⇒ Object
- #run(files) ⇒ Object
- #run_task(files, task) ⇒ Object
- #task_run ⇒ Object
Constructor Details
#initialize(output) ⇒ TaskManager
Returns a new instance of TaskManager.
3 4 5 6 |
# File 'lib/task_manager.rb', line 3 def initialize(output) @output = output @tasks = [] end |
Instance Method Details
#add(task) ⇒ Object
8 9 10 |
# File 'lib/task_manager.rb', line 8 def add(task) @tasks << task end |
#output_exception(ex) ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/task_manager.rb', line 43 def output_exception(ex) @output.add_result({ :state => :error, :title => 'Task', :summary => 'Exception', :first => ex., :detail => ex.backtrace }) end |
#run(files) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/task_manager.rb', line 12 def run(files) @num_tasks_run = 0 @tasks.each do |task| begin break if !run_task(files, task) rescue Exception => ex output_exception(ex) end end end |
#run_task(files, task) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/task_manager.rb', line 26 def run_task(files, task) result = task.run(files) return true if result.nil? task_run @output.add_result(result) return !([:error, :failure].include? result[:state]) end |
#task_run ⇒ Object
36 37 38 39 40 41 |
# File 'lib/task_manager.rb', line 36 def task_run @num_tasks_run += 1 if (@num_tasks_run == 1) @output.start_run end end |