mirror of
https://github.com/capistrano/capistrano
synced 2023-03-27 23:21:18 -04:00
before/after hooks for a namespace's default task can be named after the namespace, instead of "before_default", etc.
git-svn-id: http://svn.rubyonrails.org/rails/tools/capistrano@6461 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
parent
8cca3f8b77
commit
530dfe6a06
3 changed files with 45 additions and 23 deletions
|
@ -73,7 +73,7 @@ module Capistrano
|
|||
# Executes the task with the given name, including the before and after
|
||||
# hooks.
|
||||
def execute_task(task)
|
||||
before = task.namespace.search_task("before_#{task.name}")
|
||||
before = find_hook(task, :before)
|
||||
execute_task(before) if before
|
||||
logger.debug "executing `#{task.fully_qualified_name}'"
|
||||
|
||||
|
@ -84,7 +84,7 @@ module Capistrano
|
|||
pop_task_call_frame
|
||||
end
|
||||
|
||||
after = task.namespace.search_task("after_#{task.name}")
|
||||
after = find_hook(task, :after)
|
||||
execute_task(after) if after
|
||||
result
|
||||
end
|
||||
|
@ -97,32 +97,41 @@ module Capistrano
|
|||
execute_task(task)
|
||||
end
|
||||
|
||||
protected
|
||||
protected
|
||||
|
||||
def rollback!
|
||||
# throw the task back on the stack so that roles are properly
|
||||
# interpreted in the scope of the task in question.
|
||||
rollback_requests.reverse.each do |frame|
|
||||
begin
|
||||
push_task_call_frame(frame.task)
|
||||
logger.important "rolling back", frame.task.fully_qualified_name
|
||||
frame.rollback.call
|
||||
rescue Object => e
|
||||
logger.info "exception while rolling back: #{e.class}, #{e.message}", frame.task.fully_qualified_name
|
||||
ensure
|
||||
pop_task_call_frame
|
||||
end
|
||||
def find_hook(task, hook)
|
||||
if task == task.namespace.default_task
|
||||
result = task.namespace.search_task("#{hook}_#{task.namespace.name}")
|
||||
return result if result
|
||||
end
|
||||
|
||||
task.namespace.search_task("#{hook}_#{task.name}")
|
||||
end
|
||||
|
||||
def rollback!
|
||||
# throw the task back on the stack so that roles are properly
|
||||
# interpreted in the scope of the task in question.
|
||||
rollback_requests.reverse.each do |frame|
|
||||
begin
|
||||
push_task_call_frame(frame.task)
|
||||
logger.important "rolling back", frame.task.fully_qualified_name
|
||||
frame.rollback.call
|
||||
rescue Object => e
|
||||
logger.info "exception while rolling back: #{e.class}, #{e.message}", frame.task.fully_qualified_name
|
||||
ensure
|
||||
pop_task_call_frame
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def push_task_call_frame(task)
|
||||
frame = TaskCallFrame.new(task)
|
||||
task_call_frames.push frame
|
||||
end
|
||||
def push_task_call_frame(task)
|
||||
frame = TaskCallFrame.new(task)
|
||||
task_call_frames.push frame
|
||||
end
|
||||
|
||||
def pop_task_call_frame
|
||||
task_call_frames.pop
|
||||
end
|
||||
def pop_task_call_frame
|
||||
task_call_frames.pop
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -137,6 +137,7 @@ class ConfigurationExecutionTest < Test::Unit::TestCase
|
|||
@config.expects(:execute_task).with(:found)
|
||||
assert_nothing_raised { @config.find_and_execute_task("path:to:task") }
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def stack_inspector
|
||||
|
|
|
@ -66,4 +66,16 @@ class ConfigurationTest < Test::Unit::TestCase
|
|||
assert @config[:called_first]
|
||||
assert !@config[:called_inner_first]
|
||||
end
|
||||
|
||||
def test_hooks_for_default_task_should_be_found_if_named_after_the_namespace
|
||||
@config.namespace(:outer) do
|
||||
task(:default) { set :called_default, true }
|
||||
task(:before_outer) { set :called_before_outer, true }
|
||||
task(:after_outer) { set :called_after_outer, true }
|
||||
end
|
||||
@config.outer.default
|
||||
assert @config[:called_before_outer]
|
||||
assert @config[:called_default]
|
||||
assert @config[:called_after_outer]
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue