soveran-micromachine 0.0.2 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
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) do
10
+ if fsm.fire(:confirm)
11
11
  puts "Confirmed"
12
12
  end
13
13
 
14
- fsm.fire(:ignore) do
14
+ if fsm.fire(:ignore)
15
15
  puts "Ignored"
16
16
  end
17
17
 
18
- fsm.fire(:reset) do
18
+ if fsm.fire(:reset)
19
19
  puts "Reset"
20
20
  end
21
21
 
22
- fsm.fire(:ignore) do
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) do
11
+ if fsm.fire(:confirm)
12
12
  puts "Confirmed"
13
13
  end
14
14
 
15
- fsm.fire(:ignore) do
15
+ if fsm.fire(:ignore)
16
16
  puts "Ignored"
17
17
  end
18
18
 
19
- fsm.fire(:reset) do
19
+ if fsm.fire(:reset)
20
20
  puts "Reset"
21
21
  end
22
22
 
23
- fsm.fire(:ignore) do
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 { |hash, key| hash[:key] = [] }
22
+ @events = Hash.new
23
23
  end
24
24
 
25
25
  def fire event
26
- if new_state = events[event][@state]
27
- yield if block_given?
28
- @state = new_state
26
+ if events[event][@state]
27
+ @state = events[event][@state]
29
28
  end
30
29
  end
31
30
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: soveran-micromachine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michel Martens