diff --git a/README.rdoc b/README.rdoc index c8901f0..223ea50 100644 --- a/README.rdoc +++ b/README.rdoc @@ -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. diff --git a/lib/aasm.rb b/lib/aasm.rb index 5e0fe00..54bb002 100644 --- a/lib/aasm.rb +++ b/lib/aasm.rb @@ -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) diff --git a/lib/event.rb b/lib/event.rb index 2c7bed3..af24d30 100644 --- a/lib/event.rb +++ b/lib/event.rb @@ -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|