Class: Serially::TaskManager
- Inherits:
-
Object
- Object
- Serially::TaskManager
- Defined in:
- lib/serially/task_manager.rb
Instance Attribute Summary collapse
-
#klass ⇒ Object
Returns the value of attribute klass.
-
#options ⇒ Object
Returns the value of attribute options.
-
#queue ⇒ Object
Returns the value of attribute queue.
-
#tasks ⇒ Object
Returns the value of attribute tasks.
Class Method Summary collapse
-
.[](klass) ⇒ Object
the following two methods provide the storage of all task managers.
- .[]=(klass, task_manager) ⇒ Object
Instance Method Summary collapse
- #add_task(task_name, task_options, &block) ⇒ Object
- #clone_for(new_klass) ⇒ Object
-
#each ⇒ Object
Allow iterating over tasks.
-
#initialize(klass, options = {}) ⇒ TaskManager
constructor
A new instance of TaskManager.
Constructor Details
#initialize(klass, options = {}) ⇒ TaskManager
Returns a new instance of TaskManager.
15 16 17 18 19 20 21 |
# File 'lib/serially/task_manager.rb', line 15 def initialize(klass, = {}) @klass = klass @options = # Hash is ordered since Ruby 1.9 @tasks = {} @last_task_order = 0 end |
Instance Attribute Details
#klass ⇒ Object
Returns the value of attribute klass.
13 14 15 |
# File 'lib/serially/task_manager.rb', line 13 def klass @klass end |
#options ⇒ Object
Returns the value of attribute options.
13 14 15 |
# File 'lib/serially/task_manager.rb', line 13 def @options end |
#queue ⇒ Object
Returns the value of attribute queue.
13 14 15 |
# File 'lib/serially/task_manager.rb', line 13 def queue @queue end |
#tasks ⇒ Object
Returns the value of attribute tasks.
13 14 15 |
# File 'lib/serially/task_manager.rb', line 13 def tasks @tasks end |
Class Method Details
.[](klass) ⇒ Object
the following two methods provide the storage of all task managers
5 6 7 |
# File 'lib/serially/task_manager.rb', line 5 def self.[](klass) (@task_managers ||= {})[klass.to_s] end |
.[]=(klass, task_manager) ⇒ Object
9 10 11 |
# File 'lib/serially/task_manager.rb', line 9 def self.[]=(klass, task_manager) (@task_managers ||= {})[klass.to_s] = task_manager end |
Instance Method Details
#add_task(task_name, task_options, &block) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/serially/task_manager.rb', line 34 def add_task(task_name, , &block) raise Serially::ConfigurationError.new("Task #{task_name} is already defined in class #{@klass}") if @tasks.include?(task_name) raise Serially::ConfigurationError.new("Task name #{task_name} defined in class #{@klass} is not a symbol") if !task_name.is_a?(Symbol) = Serially::TaskOptions.validate() raise Serially::ConfigurationError.new("Task #{task_name} received the following invalid options: #{}") if .present? @tasks[task_name] = Serially::Task.new(task_name, next_task_order!, , self, &block) end |
#clone_for(new_klass) ⇒ Object
27 28 29 30 31 |
# File 'lib/serially/task_manager.rb', line 27 def clone_for(new_klass) new_mgr = TaskManager.new(new_klass, self.) self.each { |task| new_mgr.add_task(task.name, task., &task.run_block) } new_mgr end |
#each ⇒ Object
Allow iterating over tasks
45 46 47 48 49 50 51 |
# File 'lib/serially/task_manager.rb', line 45 def each return enum_for(:each) unless block_given? # return Enumerator @tasks.values.each do |task| yield task end end |