soveran-micromachine 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +0 -4
- data/example/micromachine_sample.rb +4 -4
- data/example/micromachine_sample_gem.rb +4 -4
- data/lib/micromachine.rb +3 -4
- metadata +1 -1
data/README.rdoc
CHANGED
@@ -18,10 +18,6 @@ Minimal Finite State Machine.
|
|
18
18
|
fsm.fire(:reset) #=> true
|
19
19
|
fsm.fire(:ignore) #=> true
|
20
20
|
|
21
|
-
fsm.fire(:reset) do
|
22
|
-
puts "Executed only if the transition succeeds"
|
23
|
-
end
|
24
|
-
|
25
21
|
== Installation
|
26
22
|
|
27
23
|
$ gem sources -a http://gems.github.com (you only have to do this once)
|
@@ -7,18 +7,18 @@ fsm.events[:reset] = { :confirmed => :pending, :ignored => :pending }
|
|
7
7
|
|
8
8
|
puts "Should print Confirmed, Reset and Ignored."
|
9
9
|
|
10
|
-
fsm.fire(:confirm)
|
10
|
+
if fsm.fire(:confirm)
|
11
11
|
puts "Confirmed"
|
12
12
|
end
|
13
13
|
|
14
|
-
fsm.fire(:ignore)
|
14
|
+
if fsm.fire(:ignore)
|
15
15
|
puts "Ignored"
|
16
16
|
end
|
17
17
|
|
18
|
-
fsm.fire(:reset)
|
18
|
+
if fsm.fire(:reset)
|
19
19
|
puts "Reset"
|
20
20
|
end
|
21
21
|
|
22
|
-
fsm.fire(:ignore)
|
22
|
+
if fsm.fire(:ignore)
|
23
23
|
puts "Ignored"
|
24
24
|
end
|
@@ -8,18 +8,18 @@ fsm.events[:reset] = { :confirmed => :pending, :ignored => :pending }
|
|
8
8
|
|
9
9
|
puts "Should print Confirmed, Reset and Ignored."
|
10
10
|
|
11
|
-
fsm.fire(:confirm)
|
11
|
+
if fsm.fire(:confirm)
|
12
12
|
puts "Confirmed"
|
13
13
|
end
|
14
14
|
|
15
|
-
fsm.fire(:ignore)
|
15
|
+
if fsm.fire(:ignore)
|
16
16
|
puts "Ignored"
|
17
17
|
end
|
18
18
|
|
19
|
-
fsm.fire(:reset)
|
19
|
+
if fsm.fire(:reset)
|
20
20
|
puts "Reset"
|
21
21
|
end
|
22
22
|
|
23
|
-
fsm.fire(:ignore)
|
23
|
+
if fsm.fire(:ignore)
|
24
24
|
puts "Ignored"
|
25
25
|
end
|
data/lib/micromachine.rb
CHANGED
@@ -19,13 +19,12 @@ class MicroMachine
|
|
19
19
|
|
20
20
|
def initialize initial_state
|
21
21
|
@state = initial_state
|
22
|
-
@events = Hash.new
|
22
|
+
@events = Hash.new
|
23
23
|
end
|
24
24
|
|
25
25
|
def fire event
|
26
|
-
if
|
27
|
-
|
28
|
-
@state = new_state
|
26
|
+
if events[event][@state]
|
27
|
+
@state = events[event][@state]
|
29
28
|
end
|
30
29
|
end
|
31
30
|
end
|