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
|
# Executes the task with the given name, including the before and after
|
||||||
# hooks.
|
# hooks.
|
||||||
def execute_task(task)
|
def execute_task(task)
|
||||||
before = task.namespace.search_task("before_#{task.name}")
|
before = find_hook(task, :before)
|
||||||
execute_task(before) if before
|
execute_task(before) if before
|
||||||
logger.debug "executing `#{task.fully_qualified_name}'"
|
logger.debug "executing `#{task.fully_qualified_name}'"
|
||||||
|
|
||||||
|
@ -84,7 +84,7 @@ module Capistrano
|
||||||
pop_task_call_frame
|
pop_task_call_frame
|
||||||
end
|
end
|
||||||
|
|
||||||
after = task.namespace.search_task("after_#{task.name}")
|
after = find_hook(task, :after)
|
||||||
execute_task(after) if after
|
execute_task(after) if after
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
|
@ -99,6 +99,15 @@ module Capistrano
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
|
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!
|
def rollback!
|
||||||
# throw the task back on the stack so that roles are properly
|
# throw the task back on the stack so that roles are properly
|
||||||
# interpreted in the scope of the task in question.
|
# interpreted in the scope of the task in question.
|
||||||
|
|
|
@ -137,6 +137,7 @@ class ConfigurationExecutionTest < Test::Unit::TestCase
|
||||||
@config.expects(:execute_task).with(:found)
|
@config.expects(:execute_task).with(:found)
|
||||||
assert_nothing_raised { @config.find_and_execute_task("path:to:task") }
|
assert_nothing_raised { @config.find_and_execute_task("path:to:task") }
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def stack_inspector
|
def stack_inspector
|
||||||
|
|
|
@ -66,4 +66,16 @@ class ConfigurationTest < Test::Unit::TestCase
|
||||||
assert @config[:called_first]
|
assert @config[:called_first]
|
||||||
assert !@config[:called_inner_first]
|
assert !@config[:called_inner_first]
|
||||||
end
|
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
|
end
|
||||||
|
|
Loading…
Reference in a new issue