-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
do_groceries.rb
55 lines (46 loc) · 996 Bytes
/
do_groceries.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
require 'pallets'
class DoGroceries < Pallets::Workflow
task 'EnterShop'
task 'GetShoppingCart' => 'EnterShop'
task 'PutMilk' => 'GetShoppingCart'
task 'PutBread' => 'GetShoppingCart'
task 'Pay' => ['PutMilk', 'PutBread']
task 'GoHome' => 'Pay'
end
class EnterShop < Pallets::Task
def run
puts "Entering #{context['shop_name']}"
end
end
class GetShoppingCart < Pallets::Task
def run
puts "Where's that 50 cent coin??"
context['need_to_return_coin'] = true
end
end
class PutMilk < Pallets::Task
def run
puts "Whole or half? Hmm..."
sleep 1
end
end
class PutBread < Pallets::Task
def run
puts "Got the bread"
end
end
class Pay < Pallets::Task
def run
puts "Paying by #{context['pay_by']}"
sleep 2
end
end
class GoHome < Pallets::Task
def run
puts "Done!!"
if context['need_to_return_coin']
puts '...forgot to get my coin back...'
end
end
end
DoGroceries.new(shop_name: 'Pallet Shop', pay_by: :card).run