1
0
Fork 0
mirror of https://github.com/aasm/aasm synced 2023-03-27 23:22:41 -04:00

Adjusted new callback ordering and added extra accessors for inspection.

This commit is contained in:
Scott Petersen 2009-03-02 17:47:46 -06:00
parent 6e16196f20
commit 8650fb673b
3 changed files with 21 additions and 8 deletions

View file

@ -17,18 +17,21 @@ The only changes I've made are creating more callbacks with slightly more obviou
The callback chain & order on a successful event looks like:
oldstate:exit
transition:on_transition
newstate:enter
oldstate:exit*
event:before
__find transition, if possible__
transition:on_transition*
newstate:enter*
oldstate:before_exit
newstate:before_enter
event:before
__update state__
oldstate:after_exit
oldstate:after_enter
event:after
event:success
obj:aasm_event_fired
event:success*
obj:aasm_event_fired*
(*) marks old callbacks
Note that the old callbacks haven't been removed and still have their same semantics. All of this behavior was added without removing any old behavior.

View file

@ -131,6 +131,9 @@ module AASM
old_state.call_action(:exit, self)
# new event before callback
event.call_action(:before, self)
new_state_name = event.fire(self, *args)
unless new_state_name.nil?
@ -139,7 +142,6 @@ module AASM
# new before_ callbacks
old_state.call_action(:before_exit, self)
new_state.call_action(:before_enter, self)
event.call_action(:before, self)
new_state.call_action(:enter, self)

View file

@ -3,7 +3,7 @@ require File.join(File.dirname(__FILE__), 'state_transition')
module AASM
module SupportingClasses
class Event
attr_reader :name, :success
attr_reader :name, :success, :options
def initialize(name, options = {}, &block)
@name = name
@ -32,6 +32,10 @@ module AASM
def transitions_from_state?(state)
@transitions.any? { |t| t.from == state }
end
def transitions_from_state(state)
@transitions.select { |t| t.from == state }
end
def execute_success_callback(obj)
case success
@ -56,6 +60,10 @@ module AASM
end
end
def all_transitions
@transitions
end
private
def transitions(trans_opts)
Array(trans_opts[:from]).each do |s|