Class: PetitFelix::TaskManager
- Inherits:
-
Object
- Object
- PetitFelix::TaskManager
- Defined in:
- lib/felix/task_manager.rb
Instance Method Summary collapse
-
#err_no_task_found(task, additional_text: "") ⇒ Object
No task found error.
-
#get_task(name) ⇒ Object
Gets an instance of a task.
-
#get_task_options(name) ⇒ Object
Gets options of a task.
-
#initialize ⇒ TaskManager
constructor
Gets the list of tasks loaded.
- #load_task(filename) ⇒ Object
Constructor Details
#initialize ⇒ TaskManager
Gets the list of tasks loaded
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 |
# File 'lib/felix/task_manager.rb', line 13 def initialize @error_printer = PetitFelix::Error.new @task_list = {} File.join("..","task","template_pdf_task.rb") load_task File.join(File.dirname(__FILE__),"..","task","template_pdf_task.rb") load_task File.join(File.dirname(__FILE__),"..","task","pdf_single_task.rb") load_task File.join(File.dirname(__FILE__),"..","task","basic_pdf_classic_task.rb") task_list = PetitFelix::Task.constants.select {|c| PetitFelix::Task.const_get(c).is_a? Class} task_list.delete(:DefaultTask) task_list.each do |task| task_instance = PetitFelix::Task.const_get(task) task_obj = {} task_obj["id"] = task task_obj["options"] = task_instance. name = task_instance.name @task_list[name] = task_obj end end |
Instance Method Details
#err_no_task_found(task, additional_text: "") ⇒ Object
No task found error
75 76 77 78 79 80 81 82 83 |
# File 'lib/felix/task_manager.rb', line 75 def err_no_task_found task, additional_text: "" text = "Task #{task.downcase} not found. Make sure the variable \"task\" is set correctly in your configuration settings. Available Tasks: " @task_list.keys.each do |key| text += "\n #{key}" end @error_printer.print_err text end |
#get_task(name) ⇒ Object
Gets an instance of a task
43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/felix/task_manager.rb', line 43 def get_task name if @task_list.include?(name) return PetitFelix::Task.const_get(@task_list[name]["id"]).new else if name.nil? name = "[UNDEFINED]" end err_no_task_found name, additional_text: "Unable to find task #{name}:\n" end return nil end |
#get_task_options(name) ⇒ Object
Gets options of a task
59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/felix/task_manager.rb', line 59 def name if @task_list.include?(name) return @task_list[name]["options"] else if name.nil? name = "[UNDEFINED]" end err_no_task_found name, additional_text: "Unable to get options for Task #{name}:\n" end return nil end |
#load_task(filename) ⇒ Object
7 8 9 |
# File 'lib/felix/task_manager.rb', line 7 def load_task filename load filename end |