74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
# File 'lib/fsm-0.0.0/fsm.rb', line 74
def transition state = nil, edge = nil, &b
validate_state = lambda do |state|
if state
raise TransitionError, "state == <#{ @state.inspect }> not <#{ state.inspect }>" unless
@state == state
end
end
validate_edge = lambda do |edge|
if edge
raise TransitionError, "no path <#{ state }> -->> <#{ edge }>" unless
@graph.links_from(state).map{|link| link.info}.include? edge
end
end
ex{
validate_state[state]
state ||= @state
validate_edge[edge]
edge ||= 'default'
notify Event::Exit
@state = [@state, edge]
notify Event::Transition
bcall b, *@state if b
begin
@state = @graph.transition *@state
rescue => e
m,c,b = e.message, e.class, e.backtrace.join("\n")
raise TransitionError, "#{ m } (#{ c })\n#{ b }"
end
notify Event::Entry
@state
}
end
|