Class: Employer::Workshop

Inherits:
Object
  • Object
show all
Defined in:
lib/employer/workshop.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_code, skip_employees = false) ⇒ Workshop

Returns a new instance of Workshop.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/employer/workshop.rb', line 11

def initialize(config_code, skip_employees = false)
  @logger = Employer::Logger.new
  @boss = Employer::Boss.new(logger)
  @forking_employees = 0
  @threading_employees = 0

  instance_eval(config_code)

  unless skip_employees
    @forking_employees.times do
      @boss.allocate_employee(Employer::Employees::ForkingEmployee.new(logger))
    end

    @threading_employees.times do
      @boss.allocate_employee(Employer::Employees::ThreadingEmployee.new(logger))
    end
  end
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



5
6
7
# File 'lib/employer/workshop.rb', line 5

def logger
  @logger
end

Class Method Details

.pipeline(filename) ⇒ Object



7
8
9
# File 'lib/employer/workshop.rb', line 7

def self.pipeline(filename)
  new(File.read(filename), true).pipeline
end

Instance Method Details

#log_to(log_to_logger) ⇒ Object



47
48
49
# File 'lib/employer/workshop.rb', line 47

def log_to(log_to_logger)
  logger.append_to(log_to_logger)
end

#pipelineObject



43
44
45
# File 'lib/employer/workshop.rb', line 43

def pipeline
  @boss.pipeline
end

#runObject



30
31
32
# File 'lib/employer/workshop.rb', line 30

def run
  @boss.manage
end

#stopObject



34
35
36
# File 'lib/employer/workshop.rb', line 34

def stop
  @boss.stop_managing
end

#stop_nowObject



38
39
40
41
# File 'lib/employer/workshop.rb', line 38

def stop_now
  @boss.stop_managing
  @boss.stop_employees
end