#11 new
Kai Schlichting

[Patch] Define state actions as method array

Reported by Kai Schlichting | January 29th, 2009 @ 05:09 AM

As I can see, enter and exit actions of a state can be a method as a symbol or a proc. To call several methods in an action, I do the following:

  aasm_state :my_state, :enter => proc{ |my_object|

Much prettier would be:

  aasm_state :my_state, :enter => [:method1, :method2]

Comments and changes to this ticket

  • Nathaniel Bibler

    Nathaniel Bibler March 11th, 2009 @ 01:46 PM

    • Tag set to callbacks, feature, patch

    Here's a patch that I think resolves your problem. Pretty simple, actually ...

  • Nathaniel Bibler

    Nathaniel Bibler March 11th, 2009 @ 04:00 PM

    Actually, here's a better patch that supports multiple callbacks for all areas (except guards).

    I created a separate Callbacks module which contains the execution logic for the callbacks. This should work out better in the long run for maintainability, vs just repeating the same code in three different files.

    I didn't mess with the guard logic, because it could be a bit of a gray area. My thought would be if any of the given calls return false, then the guard fails, but ... that's not for me to decide. :)

  • Nathaniel Bibler

    Nathaniel Bibler April 8th, 2009 @ 03:33 PM

    • Title changed from “Define state actions as method array” to “[Patch] Define state actions as method array”
  • Travis Tilley

    Travis Tilley October 24th, 2009 @ 01:25 AM

    you can now pass in an array for event actions, state actions, and transition actions. so this is resolved in the latest AASM.

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

Library for adding state machines to Ruby classes. Includes persistence layers for things like ActiveRecord. Formerly known as acts_as_state_machine.