Class: Adrian::Worker

Inherits:
Object
  • Object
show all
Defined in:
lib/adrian/worker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(item) ⇒ Worker

Returns a new instance of Worker.



5
6
7
# File 'lib/adrian/worker.rb', line 5

def initialize(item)
  @item = item
end

Instance Attribute Details

#itemObject (readonly)

Returns the value of attribute item.



3
4
5
# File 'lib/adrian/worker.rb', line 3

def item
  @item
end

Instance Method Details

#performObject



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/adrian/worker.rb', line 13

def perform
  exception = nil

  begin
    work
  rescue Exception => e
    exception = e
  end

  @boss.work_done(item, self, exception) if @boss
end

#report_to(boss) ⇒ Object



9
10
11
# File 'lib/adrian/worker.rb', line 9

def report_to(boss)
  @boss = boss
end

#workObject



25
26
27
# File 'lib/adrian/worker.rb', line 25

def work
  raise "You need to implement #{self.class.name}#work"
end