def define_action_helpers(action_hook = self.action)
private_action = owner_class.private_method_defined?(action_hook)
action_defined = @action_helper_defined = owner_class.ancestors.any? do |ancestor|
ancestor != owner_class && (ancestor.method_defined?(action_hook) || ancestor.private_method_defined?(action_hook))
end
action_overridden = owner_class.state_machines.any? {|name, machine| machine.action == action && machine != self}
if action_defined && !action_overridden
action = self.action
@instance_helper_module.class_eval do
define_method(action_hook) do |*args|
self.class.state_machines.transitions(self, action).perform { super(*args) }
end
private action_hook if private_action
end
true
else
false
end
end