set_callback
- 1.0.0
- 1.1.6
- 1.2.6
- 2.0.3
- 2.1.0
- 2.2.1
- 2.3.8
- 3.0.0 (0)
- 3.0.9 (-1)
- 3.1.0 (32)
- 3.2.1 (0)
- 3.2.8 (0)
- 3.2.13 (0)
- 4.0.2 (-20)
- 4.1.8 (0)
- 4.2.1 (0)
- 4.2.7 (3)
- 4.2.9 (0)
- 5.0.0.1 (0)
- 5.1.7
- 5.2.3
- 6.0.0
- 6.1.3.1
- 6.1.7.7
- 7.0.0
- 7.1.3.2
- 7.1.3.4
- What's this?
set_callback(name, *filter_list, &block)
public
Set callbacks for a previously defined callback.
Syntax:
set_callback :save, :before, :before_meth set_callback :save, :after, :after_meth, :if => :condition set_callback :save, :around, lambda { |r| stuff; yield; stuff }
Use skip_callback to skip any defined one.
When creating or skipping callbacks, you can specify conditions that are always the same for a given key. For instance, in Action Pack, we convert :only and :except conditions into per-key conditions.
before_filter :authenticate, :except => "index"
becomes
dispatch_callback :before, :authenticate, :per_key => {:unless => proc {|c| c.action_name == "index"}}
Per-Key conditions are evaluated only once per use of a given key. In the case of the above example, you would do:
run_callbacks(:dispatch, action_name) { ... dispatch stuff ... }
In that case, each action_name would get its own compiled callback method that took into consideration the per_key conditions. This is a speed improvement for ActionPack.