def define_event_helpers
define_helper(:instance, attribute(:events)) do |machine, object, *args|
machine.events.valid_for(object, *args).map {|event| event.name}
end
define_helper(:instance, attribute(:transitions)) do |machine, object, *args|
machine.events.transitions_for(object, *args)
end
if action
event_attribute = attribute(:event)
define_helper(:instance, event_attribute) do |machine, object|
event = machine.read(object, :event, true)
event && !(event.respond_to?(:empty?) && event.empty?) ? event.to_sym : nil
end
define_helper(:instance, "#{event_attribute}=") do |machine, object, value|
machine.write(object, :event, value, true)
end
event_transition_attribute = attribute(:event_transition)
define_helper :instance, "protected; attr_accessor \#{event_transition_attribute.inspect}\n", __FILE__, __LINE__ + 1
end
end