public
Description: Remote multi-server automation tool
Homepage: http://www.capify.org
Clone URL: git://github.com/jamis/capistrano.git
Search Repo:
Added support for start and finish callbacks, which get invoked when any 
task is called via the command-line


git-svn-id: http://svn.rubyonrails.org/rails/tools/capistrano@6708 
5ecf4fe2-1ee6-0310-87b1-e25e094e27de
jamis (author)
Tue May 08 22:14:37 -0700 2007
commit  5244693bfe2a7b33274c5fd0871ad7831e3cd4e3
tree    012cbfff8d1974a30a01d78f7f4163922163f641
parent  1493fb1ea6deb0b743527bcb1c7fb49c6294b999
...
1
2
 
 
3
4
5
...
1
2
3
4
5
6
7
0
@@ -1,5 +1,7 @@
0
 *SVN*
0
 
0
+* Added support for start and finish callbacks, which get invoked when any task is called via the command-line [Jamis Buck]
0
+
0
 * Make `capify' understand simple command-line switches [Jamis Buck]
0
 
0
 * Make the server definition itself available to SSH channels, rather than just the host name [Jamis Buck]
...
36
37
38
39
 
 
 
 
40
41
42
...
36
37
38
 
39
40
41
42
43
44
45
0
@@ -36,7 +36,10 @@ module Capistrano
0
 
0
       def execute_requested_actions(config)
0
         Array(options[:vars]).each { |name, value| config.set(name, value) }
0
- Array(options[:actions]).each { |action| config.find_and_execute_task(action) }
0
+
0
+ Array(options[:actions]).each do |action|
0
+ config.find_and_execute_task(action, :before => :start, :after => :finish)
0
+ end
0
       end
0
 
0
       def set_pre_vars(config) #:nodoc:
...
85
86
87
88
 
89
90
 
 
 
 
 
 
91
92
93
...
85
86
87
 
88
89
 
90
91
92
93
94
95
96
97
98
0
@@ -85,9 +85,14 @@ module Capistrano
0
       # Attempts to locate the task at the given fully-qualified path, and
0
       # execute it. If no such task exists, a Capistrano::NoSuchTaskError will
0
       # be raised.
0
- def find_and_execute_task(path)
0
+ def find_and_execute_task(path, hooks={})
0
         task = find_task(path) or raise NoSuchTaskError, "the task `#{path}' does not exist"
0
- execute_task(task)
0
+
0
+ trigger(hooks[:before], task) if hooks[:before]
0
+ result = execute_task(task)
0
+ trigger(hooks[:after], task) if hooks[:after]
0
+
0
+ result
0
       end
0
 
0
     protected
...
78
79
80
81
82
 
 
83
84
85
...
78
79
80
 
 
81
82
83
84
85
0
@@ -78,8 +78,8 @@ class CLIExecuteTest < Test::Unit::TestCase
0
     @cli.options[:actions] = %w(first second)
0
     @config.expects(:set).with(:foo, "bar")
0
     @config.expects(:set).with(:baz, "bang")
0
- @config.expects(:find_and_execute_task).with("first")
0
- @config.expects(:find_and_execute_task).with("second")
0
+ @config.expects(:find_and_execute_task).with("first", :before => :start, :after => :finish)
0
+ @config.expects(:find_and_execute_task).with("second", :before => :start, :after => :finish)
0
     @cli.execute!
0
   end
0
 
...
127
128
129
 
 
 
 
 
 
 
 
 
 
 
 
 
 
130
131
132
...
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
0
@@ -127,6 +127,20 @@ class ConfigurationExecutionTest < Test::Unit::TestCase
0
     assert_nothing_raised { @config.find_and_execute_task("path:to:task") }
0
   end
0
 
0
+ def test_find_and_execute_task_with_before_option_should_trigger_callback
0
+ @config.expects(:find_task).with("path:to:task").returns(:found)
0
+ @config.expects(:trigger).with(:incoming, :found)
0
+ @config.expects(:execute_task).with(:found)
0
+ @config.find_and_execute_task("path:to:task", :before => :incoming)
0
+ end
0
+
0
+ def test_find_and_execute_task_with_after_option_should_trigger_callback
0
+ @config.expects(:find_task).with("path:to:task").returns(:found)
0
+ @config.expects(:trigger).with(:outgoing, :found)
0
+ @config.expects(:execute_task).with(:found)
0
+ @config.find_and_execute_task("path:to:task", :after => :outgoing)
0
+ end
0
+
0
   private
0
 
0
     def stack_inspector

Comments

    No one has commented yet.