21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/yasm/manager.rb', line 21
def execute(options)
context = options[:context]
actions = options[:actions]
state_container = options[:state_container]
actions.each do |action|
action = action.new if action.class == Class
action.context = context
action.state_container = state_container
if state_container.state.class.final?
raise Yasm::FinalStateException, "We're sorry, but the current state `#{state_container.state}` is final. It does not accept any actions."
elsif !state_container.state.class.is_allowed?(action.class)
raise Yasm::InvalidActionException, "We're sorry, but the action `#{action.class}` is not possible given the current state `#{state_container.state}`."
end
change_state :to => action.triggers.to_class, :on => state_container if action.triggers
action.execute
end
end
|