Class: Inari::TaskManager
- Includes:
- Singleton
- Defined in:
- lib/inari/task_manager.rb
Defined Under Namespace
Classes: Task
Instance Attribute Summary collapse
-
#commands ⇒ Object
readonly
The command library associated with this TaskManager.
-
#tasks ⇒ Object
readonly
A hash of the tasks known to this TaskManager, keyed by name.
Instance Method Summary collapse
-
#define_task(name, options = {}, &block) ⇒ Object
Define a new task for this TaskManager.
-
#initialize ⇒ TaskManager
constructor
:nodoc:.
- #metaclass ⇒ Object
- #run_tasks ⇒ Object
Constructor Details
#initialize ⇒ TaskManager
:nodoc:
36 37 38 39 |
# File 'lib/inari/task_manager.rb', line 36 def initialize #:nodoc: @commands = Commands.instance @tasks = {} end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(sym, *args, &block) ⇒ Object (private)
64 65 66 67 68 69 70 71 72 |
# File 'lib/inari/task_manager.rb', line 64 def method_missing(sym, *args, &block) if Inari::configuration.respond_to?(sym) Inari::configuration.send(sym, *args, &block) elsif @commands.respond_to?(sym) @commands.send(sym, *args, &block) else super end end |
Instance Attribute Details
#commands ⇒ Object (readonly)
The command library associated with this TaskManager.
6 7 8 |
# File 'lib/inari/task_manager.rb', line 6 def commands @commands end |
#tasks ⇒ Object (readonly)
A hash of the tasks known to this TaskManager, keyed by name. The values are instances of TaskManager::Task.
10 11 12 |
# File 'lib/inari/task_manager.rb', line 10 def tasks @tasks end |
Instance Method Details
#define_task(name, options = {}, &block) ⇒ Object
Define a new task for this TaskManager. The block will be invoked when this task is called.
42 43 44 45 46 47 48 49 50 |
# File 'lib/inari/task_manager.rb', line 42 def define_task(name, ={}, &block) @tasks[name] = ([:task_class] || Task).new(name, self, ) define_method(name) do send "before_#{name}" if respond_to? "before_#{name}" result = instance_eval(&block) send "after_#{name}" if respond_to? "after_#{name}" result end end |
#metaclass ⇒ Object
58 59 60 |
# File 'lib/inari/task_manager.rb', line 58 def class << self; self; end end |
#run_tasks ⇒ Object
52 53 54 55 56 |
# File 'lib/inari/task_manager.rb', line 52 def run_tasks tasks.each do |task| TaskProcess.daemonize(self, task) end end |