ActiveModel, run after & before callbacks separately?

Hello, is there a way to run ActiveModel callbacks separately?

Usually You do it with block (see sample below), but I have composite model (for MongoDB, model with embedded models inside) and callbacks should be run on all models. In other words - the :before_create should be run on all models, after it models will be created and after it the :after_create also should be fired on every documents.

Actually it's possible use chain of nested blocks to do it, but in case of ~500 nested models the stack trace will be about the same size, and it's complicated, so I don't want to do it.

Here's the code:

  def create     run_callbacks :create do       # Your create action methods here     end   end

What I need is something like this:

  def create     run_callbacks :before_create     # Your create action methods here     run_callbacks :after_create   end

Thanks.

P.S. Also if You need to save any plain ruby object to MongoDB (also composite and nested) try this https://github.com/alexeypetrushin/mongo_db

Hm the source code in ActiveSupport Callbacks is auto-generated and very complicated (probably to optimize performance).

So, I created standalone version of callbacks, they are much simpler (but probably not so fast as ActiveSupport Callbacks)

https://github.com/alexeypetrushin/ruby_ext/blob/master/spec/more/callbacks_spec.rb