Module CouchRest::Callbacks::ClassMethods
In: lib/couchrest/mixins/callbacks.rb

Methods

Constants

CHAINS = {:before => :before, :around => :before, :after => :after} unless self.const_defined?("CHAINS")

Public Instance methods

This is called the first time a callback is called with a particular key. It creates a new callback method for the key, calculating which callbacks can be omitted because of per_key conditions.

Make the _run_save_callbacks method. The generated method takes a block that it‘ll yield to. It‘ll call the before and around filters in order, yield the block, and then run the after filters.

_run_save_callbacks do

  save

end

The _run_save_callbacks method can optionally take a key, which will be used to compile an optimized callback method for each key. See define_callbacks for more information.

Define callbacks.

Creates a <name>_callback method that you can use to add callbacks.

Syntax:

  save_callback :before, :before_meth
  save_callback :after,  :after_meth, :if => :condition
  save_callback :around {|r| stuff; yield; stuff }

The <name>_callback method also updates the run<name>_callbacks method, which is the public API to run the callbacks.

Also creates a skip_<name>_callback method that you can use to skip callbacks.

When creating or skipping callbacks, you can specify conditions that are always the same for a given key. For instance, in ActionPack, 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_dispatch_callbacks(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.

[Validate]