statemachine 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +5 -0
- data/TODO +0 -2
- data/lib/statemachine/state.rb +16 -4
- data/lib/statemachine/version.rb +1 -1
- data/spec/default_transition_spec.rb +18 -0
- metadata +3 -3
data/CHANGES
CHANGED
data/TODO
CHANGED
data/lib/statemachine/state.rb
CHANGED
@@ -3,7 +3,8 @@ module Statemachine
|
|
3
3
|
class State #:nodoc:
|
4
4
|
|
5
5
|
attr_reader :id, :statemachine, :superstate
|
6
|
-
attr_accessor :entry_action, :exit_action
|
6
|
+
attr_accessor :entry_action, :exit_action
|
7
|
+
attr_writer :default_transition
|
7
8
|
|
8
9
|
def initialize(id, superstate, state_machine)
|
9
10
|
@id = id
|
@@ -20,10 +21,21 @@ module Statemachine
|
|
20
21
|
return @superstate ? @transitions.merge(@superstate.transitions) : @transitions
|
21
22
|
end
|
22
23
|
|
23
|
-
def
|
24
|
+
def non_default_transition_for(event)
|
24
25
|
transition = @transitions[event]
|
25
|
-
transition = @superstate.
|
26
|
-
|
26
|
+
transition = @superstate.non_default_transition_for(event) if @superstate and not transition
|
27
|
+
return transition
|
28
|
+
end
|
29
|
+
|
30
|
+
def default_transition
|
31
|
+
return @default_transition if @default_transition
|
32
|
+
return @superstate.default_transition if @superstate
|
33
|
+
return nil
|
34
|
+
end
|
35
|
+
|
36
|
+
def transition_for(event)
|
37
|
+
transition = non_default_transition_for(event)
|
38
|
+
transition = default_transition if not transition
|
27
39
|
return transition
|
28
40
|
end
|
29
41
|
|
data/lib/statemachine/version.rb
CHANGED
@@ -83,5 +83,23 @@ describe "Default Transition" do
|
|
83
83
|
@sm.state.should eql(:not_default_state)
|
84
84
|
end
|
85
85
|
|
86
|
+
it "should use not use superstate's default before using it's own default" do
|
87
|
+
@sm = Statemachine.build do
|
88
|
+
superstate :super do
|
89
|
+
default :super_default
|
90
|
+
state :base do
|
91
|
+
default :base_default
|
92
|
+
end
|
93
|
+
end
|
94
|
+
state :super_default
|
95
|
+
state :base_default
|
96
|
+
startstate :base
|
97
|
+
end
|
98
|
+
|
99
|
+
@sm.blah
|
100
|
+
@sm.state.should eql(:base_default)
|
101
|
+
end
|
102
|
+
|
103
|
+
|
86
104
|
|
87
105
|
end
|
metadata
CHANGED
@@ -3,9 +3,9 @@ rubygems_version: 0.9.1
|
|
3
3
|
specification_version: 1
|
4
4
|
name: statemachine
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.4.
|
7
|
-
date: 2007-05-
|
8
|
-
summary: Statemachine-0.4.
|
6
|
+
version: 0.4.1
|
7
|
+
date: 2007-05-20 00:00:00 -07:00
|
8
|
+
summary: Statemachine-0.4.1 - Statemachine Library for Ruby http://statemachine.rubyforge.org/
|
9
9
|
require_paths:
|
10
10
|
- lib
|
11
11
|
email: statemachine-devel@rubyforge.org
|