class Beanpicker::Worker

Worker is the class used to create jobs

Attributes

childs[R]

The list of childs

name[R]

The name of worker. Pick from args or from the name of file(if passed)

Public Class Methods

new(filepath=nil, args={}, &blk) click to toggle source

Accept a file and/or a block with jobs and add itself to workers list

# File lib/beanpicker/job_server.rb, line 80
def initialize(filepath=nil, args={}, &blk)
  @childs = []
  @name   = args[:name] rescue nil
  if filepath
    @name = filepath.split(/[\\\/]/)[-1].gsub(/\.[^\.]+$/,'').split(/[_\.]/).map do |x|
      x.capitalize
    end.join if @name.nil?

    begin
      instance_eval File.read(filepath)
    rescue => e
      error Beanpicker::exception_message(e, "when loading file #{filepath}")
    end
  end

  if block_given?
    begin
      instance_eval(&blk)
    rescue => e
      error Beanpicker::exception_message(e, "when evaluating block")
    end
  end

  @name = "BeanpickerWorker without name" unless @name
  Beanpicker::add_worker(self)
end

Public Instance Methods

job(name, args={}, &blk) click to toggle source

Pass the job to Child::process and add the return to childs list

# File lib/beanpicker/job_server.rb, line 108
def job(name, args={}, &blk)
  @childs << Child.process(name, args, self, &blk)
  @childs.flatten!
end
log_file(f) click to toggle source

Shortcut to log_handler=

# File lib/beanpicker/job_server.rb, line 119
def log_file(f)
  #without self call don't call log_handler= of this class Oo
  self.log_handler = f
end
log_handler() click to toggle source

Use it own log_handler or global if not defined

# File lib/beanpicker/job_server.rb, line 114
def log_handler
  @log_handler || Beanpicker::log_handler
end