Class: Idler::Workers

Inherits:
Object
  • Object
show all
Defined in:
lib/idler/workers.rb

Instance Method Summary collapse

Constructor Details

#initializeWorkers

Returns a new instance of Workers.



4
5
6
# File 'lib/idler/workers.rb', line 4

def initialize
  @workers = {}
end

Instance Method Details

#add_branch(branch_name = nil) ⇒ Object



8
9
10
11
# File 'lib/idler/workers.rb', line 8

def add_branch(branch_name = nil)
  raise NothingBranchNameError if branch_name.nil?
  @workers[branch_name] = nil
end

#add_worker(branch_name = nil, block = nil) ⇒ Object



13
14
15
16
17
18
# File 'lib/idler/workers.rb', line 13

def add_worker(branch_name = nil, block = nil)
  raise NothingBranchNameError if branch_name.nil?
  raise NotYetAddBranchError   unless @workers.key?(branch_name)
  raise NotProcError           unless block.class == Proc
  @workers[branch_name] = block
end

#run(branch_name = nil) ⇒ Object



20
21
22
23
# File 'lib/idler/workers.rb', line 20

def run(branch_name = nil)
  raise NothingBranchNameError if branch_name.nil?
  @workers[branch_name].call   if @workers.key?(branch_name)
end