class StateMachines::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
Calls superclass method
StateMachines::TransitionCollection#persist
# File lib/state_machines/transition_collection.rb, line 229 def persist @before_run = true super end
reset()
click to toggle source
Resets callback tracking
Calls superclass method
StateMachines::TransitionCollection#reset
# File lib/state_machines/transition_collection.rb, line 235 def reset super @before_run = false end
rollback()
click to toggle source
Resets the event attribute so it can be re-evaluated if attempted again
Calls superclass method
StateMachines::TransitionCollection#rollback
# File lib/state_machines/transition_collection.rb, line 241 def rollback super each {|transition| transition.machine.write(object, :event, transition.event) unless transition.transient?} end
run_callbacks(index = 0)
click to toggle source
Hooks into running transition callbacks so that event / event transition attributes can be properly updated
Calls superclass method
StateMachines::TransitionCollection#run_callbacks
# File lib/state_machines/transition_collection.rb, line 201 def run_callbacks(index = 0) if index == 0 # Clears any traces of the event attribute to prevent it from being # evaluated multiple times if actions are nested each do |transition| transition.machine.write(object, :event, nil) transition.machine.write(object, :event_transition, nil) end # Rollback only if exceptions occur during before callbacks begin super rescue Exception rollback unless @before_run @success = nil # mimics ActiveRecord.save behavior on rollback raise end # Persists transitions on the object if partial transition was successful. # This allows us to reference them later to complete the transition with # after callbacks. each {|transition| transition.machine.write(object, :event_transition, transition)} if skip_after && success? else super end end