class EnumStateMachine::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/enum_state_machine/transition_collection.rb
228 def persist
229   @before_run = true
230   super
231 end
reset() click to toggle source

Resets callback tracking

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

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

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