jamis / capistrano

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!

This URL has Read+Write access

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