ActiveSupport callbacks: Option to replace existing callback in chain

Jonas Schwertfeger
2014-07-17T10:40:38Z

Hey,

This is to discuss your thoughts on a feature request I am willing to
implement:

Currently, when appending/prepending an ActiveSupport callback to a chain,
any existing callback of the same kind and with the same name is being
removed first and then the new callback is being added at the beginning or
the end of the chain. This obviously changes the order of the callbacks.

There are cases where one would want an already existing callback to be
replaced in-place (i.e. the new callback takes the position of the existing
callback), preserving the existing callback sequence.

One such case I have come across are controller after/before/around
actions/filters where a subclass would like to alter/replace an action that
has been defined in a super class without touching the action ordering.

I propose adding an optional boolean parameter "preserve_order", and
accompanying code, all the way from the before/after/around_action methods
in AbstractController down to the ActiveSupport callback methods to enable
such callback substitution.

Thoughts?

-Jonas

--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to rubyonrails-core+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-core@googlegroups.com.
Visit this group at http://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.