Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

[Patch] Define state actions as method array

#11

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|
    my_object.send(:method1)
    my_object.send(:method2)
  }

Much prettier would be:


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

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

State: new
Milestone: none
Assigned to: Scott Barron Scott Barron

Activity

  1. Nathaniel Bibler
    Nathaniel Bibler
    • Tag set to callbacks, feature, patch

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

    March 11th, 2009 @ 01:46 PM

  2. Nathaniel Bibler
    Nathaniel Bibler

    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. :)

    March 11th, 2009 @ 04:00 PM

  3. Nathaniel Bibler
    Nathaniel Bibler
    • Title changed from Define state actions as method array to [Patch] Define state actions as method array

    April 8th, 2009 @ 03:33 PM

  4. Travis Tilley
    Travis Tilley

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

    October 24th, 2009 @ 01:25 AM

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.