def attribute_transition_for(object, invalidate = false)
      return unless machine.action

      # TODO, simplify
      machine.read(object, :event_transition) || if event_name = machine.read(object, :event)
                                                   if event = self[event_name.to_sym, :name]
                                                     event.transition_for(object) || begin
                                                                                       # No valid transition: invalidate
                                                       machine.invalidate(object, :event, :invalid_event, [[:state, machine.states.match!(object).human_name(object.class)]]) if invalidate
                                                       false
                                                     end
                                                   else
                                                     # Event is unknown: invalidate
                                                     machine.invalidate(object, :event, :invalid) if invalidate
                                                     false
                                                   end
                                                 end

    end
def attribute_transition_for(object, invalidate = false)
      return unless machine.action

      # TODO, simplify
      machine.read(object, :event_transition) || if event_name = machine.read(object, :event)
                                                   if event = self[event_name.to_sym, :name]
                                                     event.transition_for(object) || begin
                                                                                       # No valid transition: invalidate
                                                       machine.invalidate(object, :event, :invalid_event, [[:state, machine.states.match!(object).human_name(object.class)]]) if invalidate
                                                       false
                                                     end
                                                   else
                                                     # Event is unknown: invalidate
                                                     machine.invalidate(object, :event, :invalid) if invalidate
                                                     false
                                                   end
                                                 end

    end
Gets the transition that should be performed for the event stored in the
 given object's event attribute.  This also takes an additional parameter
 for automatically invalidating the object if the event or transition are
 invalid.  By default, this is turned off.

 *Note* that if a transition has already been generated for the event, then
 that transition will be used.

 == Examples

   class Vehicle < ActiveRecord::Base
     state_machine :initial => :parked do
       event :ignite do
         transition :parked => :idling
       end
     end
   end

   vehicle = Vehicle.new                       # => #<Vehicle id: nil, state: "parked">
   events = Vehicle.state_machine.events

   vehicle.state_event = nil
   events.attribute_transition_for(vehicle)    # => nil # Event isn't defined

   vehicle.state_event = 'invalid'
   events.attribute_transition_for(vehicle)    # => false # Event is invalid

   vehicle.state_event = 'ignite'
   events.attribute_transition_for(vehicle)    # => #<StateMachines::Transition attribute=:state event=:ignite from="parked" from_name=:parked to="idling" to_name=:idling>