ActiveSupport callbacks: Option to replace existing callback in chain

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