Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access to firing event in callbacks #168

Closed
bbugh opened this issue Sep 10, 2014 · 4 comments
Closed

Access to firing event in callbacks #168

bbugh opened this issue Sep 10, 2014 · 4 comments

Comments

@bbugh
Copy link

bbugh commented Sep 10, 2014

There does not seem to be a way to access the name of the event that triggered an on_transition callback. We need this for a pubsub to record state changes event (because externally we care about triggered events and internally we care about states). In this case the to_state/from_state is not helpful, we need the particular event. There are a number of ways to hack this in our application and all of them are gross.

This would be a very helpful attribute in our case.

I looked into it a bit and it doesn't seem too hard to add :current_event to InstanceBase but the spec tests do not run (an rspec error) and I don't want to have to set up Mongo (why not sqlite?) and debug them to figure it out.

Thanks for the great state machine gem.

@rranelli
Copy link

Having access to the name of the event would fix #159 too.

@alto
Copy link
Member

alto commented Sep 12, 2014

I just released version 3.4.0 providing a way to retrieve the current event (using aasm.current_event).

Take a look at the README:

The current event triggered

While running the callbacks you can easily retrieve the name of the event triggered
by using aasm.current_event:

  # taken the example callback from above
  def do_something
    puts "triggered #{aasm.current_event}"
  end

and then

  job = Job.new

  # without bang
  job.sleep # => triggered :sleep

  # with bang
  job.sleep! # => triggered :sleep!

Please, let me know if that solves this issue!

@alto alto closed this as completed Sep 12, 2014
@bbugh
Copy link
Author

bbugh commented Sep 12, 2014

This is perfect, thank you for the work and quick turnaround! ❤️

@rranelli
Copy link

That is awesome!

The issue has been solved =)

Thank you so much for the effort.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants