class StateMachine::AttributeTransitionCollection

Represents a collection of transitions that were generated from attribute- based events

Private Instance Methods

persist() click to toggle source

Tracks that before callbacks have now completed

    # File lib/state_machine/transition_collection.rb
227 def persist
228   @before_run = true
229   super
230 end
reset() click to toggle source

Resets callback tracking

    # File lib/state_machine/transition_collection.rb
233 def reset
234   super
235   @before_run = false
236 end
rollback() click to toggle source

Resets the event attribute so it can be re-evaluated if attempted again

    # File lib/state_machine/transition_collection.rb
239 def rollback
240   super
241   each {|transition| transition.machine.write(object, :event, transition.event) unless transition.transient?}
242 end
run_callbacks(index = 0) click to toggle source

Hooks into running transition callbacks so that event / event transition attributes can be properly updated

    # File lib/state_machine/transition_collection.rb
200 def run_callbacks(index = 0)
201   if index == 0
202     # Clears any traces of the event attribute to prevent it from being
203     # evaluated multiple times if actions are nested
204     each do |transition|
205       transition.machine.write(object, :event, nil)
206       transition.machine.write(object, :event_transition, nil)
207     end
208     
209     # Rollback only if exceptions occur during before callbacks
210     begin
211       super
212     rescue Exception
213       rollback unless @before_run
214       raise
215     end
216     
217     # Persists transitions on the object if partial transition was successful.
218     # This allows us to reference them later to complete the transition with
219     # after callbacks.
220     each {|transition| transition.machine.write(object, :event_transition, transition)} if skip_after && success?
221   else
222     super
223   end
224 end