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

Global callbacks #253

Closed
fabn opened this issue Sep 4, 2015 · 15 comments
Closed

Global callbacks #253

fabn opened this issue Sep 4, 2015 · 15 comments

Comments

@fabn
Copy link

fabn commented Sep 4, 2015

It would be nice (mostly for auditing purpose) to have a set of global callbacks in this gem, something like

class Job
  include AASM
  aasm before_state_change: :log_it, before_event: :log_it_too do
    state :sleeping, :initial => true
    state :running
    event :run do
      transitions :from => :sleeping, :to => :running
    end
  end

  def log_it
    logger.info "triggered #{aasm.current_event}"
    logger.info "from #{aasm.from_state} to #{aasm.to_state}"
  end
end

What do you think?

@jeremywadsack
Copy link

+1

I was just looking at how to do this so that we can track event transition timing (and other such metrics).

@jeremywadsack
Copy link

This looks similar to #221 and #108 which is what I really want. Because I want to decorate an existing AASM model (defined in a shared gem) with callbacks (that are specific to the app) but apply the same code all transitions.

@rposborne
Copy link

+1

@alto
Copy link
Member

alto commented Sep 28, 2015

Okay, I see your point. Will work on that from now on.

@alto
Copy link
Member

alto commented Sep 28, 2015

Would this be sufficient?

  aasm do
    after_all_transitions :do_logging_or_whatever
  end

  def do_logging_or_whatever
    ...
  end

In do_logging_or_whatever you can access aasm.from_state, aasm.to_state and aasm.current_event.

@jeremywadsack
Copy link

Yeah, that works for me.

@fabn
Copy link
Author

fabn commented Sep 29, 2015

That would be good. Imho also a before callback would be nice to have a trace in case something goes wrong during transition.

@anilmaurya
Copy link
Member

@alto are you working on this feature ? If not then I can help you on this.

@alto
Copy link
Member

alto commented Oct 16, 2015

@anilmaurya Thanks for your offer. I'm sorry, I'm already working on it.

@anilmaurya
Copy link
Member

@alto No problem . Happy coding 😄

@alto
Copy link
Member

alto commented Oct 16, 2015

Please take a look at #270 and let me know if that works for your problem. Will release soon.

@fabn
Copy link
Author

fabn commented Oct 16, 2015

Awesome job, thanks.

@jeremywadsack
Copy link

Yeah, that works for me too. Thanks.

@alto
Copy link
Member

alto commented Oct 23, 2015

Closed with #270 .

@alto alto closed this as completed Oct 23, 2015
@alto
Copy link
Member

alto commented Oct 27, 2015

I just released version 4.4.0 including the change.

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

No branches or pull requests

5 participants