spree/spree — Issue #863: Use Method Name Symbols Instead of Proc Blocks in Callback Definitions
Author: jumph4x
Created: 2011-12-12 16:39:42+00:00
State: open

Docs: http://api.rubyonrails.org/classes/ActiveSupport/Callbacks/ClassMethods.html

See: https://github.com/spree/spree/blob/master/core/app/models/spree/adjustment.rb#L36

Problem:
Blocks prevent effective use of this important piece of the Rails API when manipulating the callback collection. We can clear all callbacks of a particular type, but reinstating them is a problem. Also targeting specific callbacks for a type becomes a problem.

Example:
We have an extension that registers a method with the order listener that is called every time Order#update! is called. The said extension creates Adjustment records, each of those calls Order#update! again. We have ourselves a SystemStackError. While arguably, and factually, not a fault with Spree, I believe the suggested way of registering callbacks to be cleaner and more flexible. Specifically, we should separate the callback logic from the callback registration.

If this is something you guys are interested in, I will gladly generate a pull request for master, simply let me know.