| Module | Capistrano::Configuration::Callbacks |
| In: |
lib/capistrano/configuration/callbacks.rb
lib/capistrano/configuration/callbacks.rb |
| callbacks | [R] | The hash of callbacks that have been registered for this configuration |
| callbacks | [R] | The hash of callbacks that have been registered for this configuration |
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 on method.
# File lib/capistrano/configuration/callbacks.rb, line 69
69: def after(task_name, *args, &block)
70: options = args.last.is_a?(Hash) ? args.pop : {}
71: args << options.merge(:only => task_name)
72: on :after, *args, &block
73: end
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 on method.
# File lib/capistrano/configuration/callbacks.rb, line 69
69: def after(task_name, *args, &block)
70: options = args.last.is_a?(Hash) ? args.pop : {}
71: args << options.merge(:only => task_name)
72: on :after, *args, &block
73: end
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 on method.
# File lib/capistrano/configuration/callbacks.rb, line 50
50: def before(task_name, *args, &block)
51: options = args.last.is_a?(Hash) ? args.pop : {}
52: args << options.merge(:only => task_name)
53: on :before, *args, &block
54: end
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 on method.
# File lib/capistrano/configuration/callbacks.rb, line 50
50: def before(task_name, *args, &block)
51: options = args.last.is_a?(Hash) ? args.pop : {}
52: args << options.merge(:only => task_name)
53: on :before, *args, &block
54: end
Defines one or more callbacks to be invoked in response to some event. Capistrano currently understands the following events:
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:
Usage:
on :before, "some:hook", "another:hook", :only => "deploy:update" on :after, "some:hook", :except => "deploy:symlink" on :before, "global:hook" on :after, :only => :deploy do puts "after deploy here" end
# File lib/capistrano/configuration/callbacks.rb, line 103
103: def on(event, *args, &block)
104: options = args.last.is_a?(Hash) ? args.pop : {}
105: callbacks[event] ||= []
106:
107: if args.empty? && block.nil?
108: raise ArgumentError, "please specify either a task name or a block to invoke"
109: elsif args.any? && block
110: raise ArgumentError, "please specify only a task name or a block, but not both"
111: elsif block
112: callbacks[event] << ProcCallback.new(block, options)
113: else
114: args.each do |name|
115: callbacks[event] << TaskCallback.new(self, name, options)
116: end
117: end
118: end
Defines one or more callbacks to be invoked in response to some event. Capistrano currently understands the following events:
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:
Usage:
on :before, "some:hook", "another:hook", :only => "deploy:update" on :after, "some:hook", :except => "deploy:symlink" on :before, "global:hook" on :after, :only => :deploy do puts "after deploy here" end
# File lib/capistrano/configuration/callbacks.rb, line 103
103: def on(event, *args, &block)
104: options = args.last.is_a?(Hash) ? args.pop : {}
105: callbacks[event] ||= []
106:
107: if args.empty? && block.nil?
108: raise ArgumentError, "please specify either a task name or a block to invoke"
109: elsif args.any? && block
110: raise ArgumentError, "please specify only a task name or a block, but not both"
111: elsif block
112: callbacks[event] << ProcCallback.new(block, options)
113: else
114: args.each do |name|
115: callbacks[event] << TaskCallback.new(self, name, options)
116: end
117: end
118: end
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 122
122: def trigger(event, task=nil)
123: pending = Array(callbacks[event]).select { |c| c.applies_to?(task) }
124: if pending.any?
125: msg = "triggering #{event} callbacks"
126: msg << " for `#{task.fully_qualified_name}'" if task
127: logger.trace(msg)
128: pending.each { |callback| callback.call }
129: end
130: end
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 122
122: def trigger(event, task=nil)
123: pending = Array(callbacks[event]).select { |c| c.applies_to?(task) }
124: if pending.any?
125: msg = "triggering #{event} callbacks"
126: msg << " for `#{task.fully_qualified_name}'" if task
127: logger.trace(msg)
128: pending.each { |callback| callback.call }
129: end
130: end