Class: Inari::TaskManager

Inherits:
Object show all
Includes:
Singleton
Defined in:
lib/inari/task_manager.rb

Defined Under Namespace

Classes: Task

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTaskManager

: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

#commandsObject (readonly)

The command library associated with this TaskManager.



6
7
8
# File 'lib/inari/task_manager.rb', line 6

def commands
  @commands
end

#tasksObject (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, options={}, &block)
  @tasks[name] = (options[:task_class] || Task).new(name, self, options)
  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

#metaclassObject



58
59
60
# File 'lib/inari/task_manager.rb', line 58

def metaclass
  class << self; self; end
end

#run_tasksObject



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