Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

root/tools/capistrano/lib/capistrano/callback.rb

Revision 7381, 1.0 kB (checked in by minam, 1 year ago)

Don't let a task trigger itself when used as the source for an "on" hook (closes #9356)

Line 
1 module Capistrano
2   class Callback
3     attr_reader :source, :options, :only, :except
4
5     def initialize(source, options={})
6       @source = source
7       @options = options
8       @only = Array(options[:only]).map { |v| v.to_s }
9       @except = Array(options[:except]).map { |v| v.to_s }
10     end
11
12     def applies_to?(task)
13       if task && only.any?
14         return only.include?(task.fully_qualified_name)
15       elsif task && except.any?
16         return !except.include?(task.fully_qualified_name)
17       else
18         return true
19       end
20     end
21   end
22
23   class ProcCallback < Callback
24     def call
25       source.call
26     end
27   end
28
29   class TaskCallback < Callback
30     attr_reader :config
31
32     def initialize(config, source, options={})
33       super(source, options)
34       @config = config
35     end
36
37     def call
38       config.find_and_execute_task(source)
39     end
40
41     def applies_to?(task)
42       super && (task.nil? || task.fully_qualified_name != source.to_s)
43     end
44   end
45 end
Note: See TracBrowser for help on using the browser.