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: The callback chain & order on a successful event looks like:
oldstate:exit oldstate:exit*
transition:on_transition event:before
newstate:enter __find transition, if possible__
transition:on_transition*
newstate:enter*
oldstate:before_exit oldstate:before_exit
newstate:before_enter newstate:before_enter
event:before
__update state__ __update state__
oldstate:after_exit oldstate:after_exit
oldstate:after_enter oldstate:after_enter
event:after event:after
event:success event:success*
obj:aasm_event_fired 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. 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) old_state.call_action(:exit, self)
# new event before callback
event.call_action(:before, self)
new_state_name = event.fire(self, *args) new_state_name = event.fire(self, *args)
unless new_state_name.nil? unless new_state_name.nil?
@ -139,7 +142,6 @@ module AASM
# new before_ callbacks # new before_ callbacks
old_state.call_action(:before_exit, self) old_state.call_action(:before_exit, self)
new_state.call_action(:before_enter, self) new_state.call_action(:before_enter, self)
event.call_action(:before, self)
new_state.call_action(:enter, self) new_state.call_action(:enter, self)

View file

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