public
Description: Remote multi-server automation tool. This repository is no longer being actively maintained. Please ask on the mailing list to find someone who has a well-maintained fork. Thanks!
Homepage: http://www.capify.org
Clone URL: git://github.com/jamis/capistrano.git
Make block-triggers scope to the task they are attached to.

Prior to this, if you defined (e.g.) a before task using a block,
like this:

  before :foo do
    puts "current task is #{current_task.name}"
  end

And then, you invoked :foo like this:

  task :bar do
    run "something"
    foo
  end

You'd see the before-foo block print "bar" as the name of the
current task. This meant that any commands run in the foo before
block would be scoped to the servers of :bar, when it really
makes more sense to scope them to the servers of :foo. This
commit makes it so that the before-foo block, above, would show
"foo" as the name of the current task, rather than "bar".
Jamis Buck (author)
Thu Jun 05 20:00:19 -0700 2008
commit  2ac1906a3ab0bda997ca3b028b9b20d222faf3fe
tree    7a296725662fbfe233f1d84045e6e8df02281cb1
parent  0d415c677dc7f13c2b4c74ed6ebe65a08c1a2339
...
1
2
 
 
3
4
5
...
1
2
3
4
5
6
7
0
@@ -1,5 +1,7 @@
0
 *unreleased*
0
 
0
+* Make sure triggers defined as a block inherit the scope of the task they are attached to, instead of the task they were called from [Jamis Buck]
0
+
0
 * Make deploy:upload use the upload() helper for more efficient directory processing [Jamis Buck]
0
 
0
 * Make deploy:upload accept globs [Mark Imbriaco]
...
4
5
6
7
 
8
9
10
...
18
19
20
21
 
22
23
24
25
26
27
 
28
29
30
...
4
5
6
 
7
8
9
10
...
18
19
20
 
21
22
23
24
25
26
 
27
28
29
30
0
@@ -4,7 +4,7 @@ module Capistrano
0
   class Configuration
0
     module Callbacks
0
       def self.included(base) #:nodoc:
0
-        %w(initialize execute_task).each do |method|
0
+        %w(initialize invoke_task_directly).each do |method|
0
           base.send :alias_method, "#{method}_without_callbacks", method
0
           base.send :alias_method, method, "#{method}_with_callbacks"
0
         end
0
@@ -18,13 +18,13 @@ module Capistrano
0
         @callbacks = {}
0
       end
0
 
0
-      def execute_task_with_callbacks(task) #:nodoc:
0
+      def invoke_task_directly_with_callbacks(task) #:nodoc:
0
         before = find_hook(task, :before)
0
         execute_task(before) if before
0
 
0
         trigger :before, task
0
 
0
-        result = execute_task_without_callbacks(task)
0
+        result = invoke_task_directly_without_callbacks(task)
0
 
0
         trigger :after, task
0
 
...
72
73
74
75
76
 
 
77
78
79
80
 
81
82
83
...
121
122
123
 
 
 
 
 
124
125
126
127
...
72
73
74
 
 
75
76
77
78
79
 
80
81
82
83
...
121
122
123
124
125
126
127
128
129
130
131
132
0
@@ -72,12 +72,12 @@ module Capistrano
0
         task_call_frames.last.task
0
       end
0
 
0
-      # Executes the task with the given name, including the before and after
0
-      # hooks.
0
+      # Executes the task with the given name, without invoking any associated
0
+      # callbacks.
0
       def execute_task(task)
0
         logger.debug "executing `#{task.fully_qualified_name}'"
0
         push_task_call_frame(task)
0
-        task.namespace.instance_eval(&task.body)
0
+        invoke_task_directly(task)
0
       ensure
0
         pop_task_call_frame
0
       end
0
@@ -121,6 +121,11 @@ module Capistrano
0
       def pop_task_call_frame
0
         task_call_frames.pop
0
       end
0
+
0
+      # Invokes the task's body directly, without setting up the call frame.
0
+      def invoke_task_directly(task)
0
+        task.namespace.instance_eval(&task.body)
0
+      end
0
     end
0
   end
0
 end
0
\ No newline at end of file
...
12
13
14
15
 
16
17
 
 
 
 
 
 
18
19
20
...
12
13
14
 
15
16
17
18
19
20
21
22
23
24
25
26
0
@@ -12,9 +12,15 @@ class ConfigurationCallbacksTest < Test::Unit::TestCase
0
     end
0
 
0
     def execute_task(task)
0
-      @called << task
0
+      invoke_task_directly(task)
0
     end
0
 
0
+    protected
0
+
0
+      def invoke_task_directly(task)
0
+        @called << task
0
+      end
0
+
0
     include Capistrano::Configuration::Callbacks
0
   end
0
 

Comments