Class Index [+]

Quicksearch

Capistrano::Configuration::Callbacks

Attributes

callbacks[R]

The hash of callbacks that have been registered for this configuration

Public Instance Methods

after(task_name, *args, &block) click to toggle source

Defines a callback to be invoked after the given task. You must specify the fully-qualified task name, both for the primary task, and for the task(s) to be executed after. Alternatively, you can pass a block to be executed after the given task.

  after "deploy:update_code", :log_difference
  after :deploy, "custom:announce"
  after :deploy, :this, "then:this", "and:then:this"
  after :some_task do
    puts "an anonymous hook!"
  end

This just provides a convenient interface to the more general # method.

    # File lib/capistrano/configuration/callbacks.rb, line 64
64:       def after(task_name, *args, &block)
65:         options = args.last.is_a?(Hash) ? args.pop : {}
66:         args << options.merge(:only => task_name)
67:         on :after, *args, &block
68:       end
before(task_name, *args, &block) click to toggle source

Defines a callback to be invoked before the given task. You must specify the fully-qualified task name, both for the primary task, and for the task(s) to be executed before. Alternatively, you can pass a block to be executed before the given task.

  before "deploy:update_code", :record_difference
  before :deploy, "custom:log_deploy"
  before :deploy, :this, "then:this", "and:then:this"
  before :some_task do
    puts "an anonymous hook!"
  end

This just provides a convenient interface to the more general # method.

    # File lib/capistrano/configuration/callbacks.rb, line 45
45:       def before(task_name, *args, &block)
46:         options = args.last.is_a?(Hash) ? args.pop : {}
47:         args << options.merge(:only => task_name)
48:         on :before, *args, &block
49:       end
on(event, *args, &block) click to toggle source

Defines one or more callbacks to be invoked in response to some event. Capistrano currently understands the following events:

  • :before, triggered before a task is invoked

  • :after, triggered after a task is invoked

  • :start, triggered before a top-level task is invoked via the command-line

  • :finish, triggered when a top-level task completes

  • :load, triggered after all recipes have loaded

  • :exit, triggered after all tasks have completed

Specify the (fully-qualified) task names that you want invoked in response to the event. Alternatively, you can specify a block to invoke when the event is triggered. You can also pass a hash of options as the last parameter, which may include either of two keys:

  • :only, should specify an array of task names. Restricts this callback so that it will only fire when the event applies to those tasks.

  • :except, should specify an array of task names. Restricts this callback so that it will never fire when the event applies to those tasks.

Usage:

 on :before, "some:hook", "another:hook", :only => "deploy:update"
 on :after, "some:hook", :except => "deploy:create_symlink"
 on :before, "global:hook"
 on :after, :only => :deploy do
   puts "after deploy here"
 end
     # File lib/capistrano/configuration/callbacks.rb, line 98
 98:       def on(event, *args, &block)
 99:         options = args.last.is_a?(Hash) ? args.pop : {}
100:         callbacks[event] ||= []
101: 
102:         if args.empty? && block.nil?
103:           raise ArgumentError, "please specify either a task name or a block to invoke"
104:         elsif args.any? && block
105:           raise ArgumentError, "please specify only a task name or a block, but not both"
106:         elsif block
107:           callbacks[event] << ProcCallback.new(block, options)
108:         else
109:           args.each do |name|
110:             callbacks[event] << TaskCallback.new(self, name, options)
111:           end
112:         end
113:       end
trigger(event, task=nil) click to toggle source

Trigger the named event for the named task. All associated callbacks will be fired, in the order they were defined.

     # File lib/capistrano/configuration/callbacks.rb, line 117
117:       def trigger(event, task=nil)
118:         pending = Array(callbacks[event]).select { |c| c.applies_to?(task) }
119:         if pending.any?
120:           msg = "triggering #{event} callbacks"
121:           msg << " for `#{task.fully_qualified_name}'" if task
122:           logger.trace(msg)
123:           pending.each { |callback| callback.call }
124:         end
125:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.