Before
- Definition
- before(task_name, *args, &block)
- Module
- Capistrano::Configuration::Callbacks
- File
- capistrano/configuration/callbacks.rb
This method lets you tell Capistrano to invoke one or more other tasks before invoking a particular task. This makes it very easy to extend an existing recipe, by adding these hooks to be executed before some task. (For adding tasks to be executed after another task, see the after method.)
Arguments
task_name
This may be either a symbol or a string that gives the fully qualified name of the task to extend. This means that if you want to extend the deploy:upload task, you must give the task name as "deploy:upload", and not merely as :upload.
The task does not have to exist at the time the callback is defined. If it does not exist, it will never be called, and the callback will never be used. If it is defined later, the callback defined by before will be remembered.
*args
This must be zero or more task names (fully qualified, as with task_name), identifying the tasks that should be executed before task_name is executed. Order is honored, here; the tasks will be executed in the order you specify them. Likewise, multiple invocations of before will imply the order in which the callbacks are invoked.
before "deploy:symlink", :symlink_database_config before "deploy:web:enable", "deploy:email:enable", "deploy:sms:enable"
&block
If a block is given, it will be treated as an anonymous task. The block itself will be invoked before task_name, and will use the same server scope as task_name. In general, using a block with before is discouraged because it makes it harder to reuse code, but there are times when it can be genuinely useful.
before "deploy:symlink" do run "#{sudo} ln -nsf /path/to/real/config.yml /u/apps/social/current/config/database.yml" end