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

root/tools/capistrano/lib/capistrano/task_definition.rb

Revision 8924, 2.2 kB (checked in by minam, 9 months ago)

Add support for :max_hosts option in task definition or run() (closes #10264)

Line 
1 require 'capistrano/server_definition'
2
3 module Capistrano
4   # Represents the definition of a single task.
5   class TaskDefinition
6     attr_reader :name, :namespace, :options, :body, :desc, :on_error, :max_hosts
7
8     def initialize(name, namespace, options={}, &block)
9       @name, @namespace, @options = name, namespace, options
10       @desc = @options.delete(:desc)
11       @on_error = options.delete(:on_error)
12       @max_hosts = options[:max_hosts] && options[:max_hosts].to_i
13       @body = block or raise ArgumentError, "a task requires a block"
14       @servers = nil
15     end
16    
17     # Returns the task's fully-qualified name, including the namespace
18     def fully_qualified_name
19       @fully_qualified_name ||= begin
20         if namespace.default_task == self
21           namespace.fully_qualified_name
22         else
23           [namespace.fully_qualified_name, name].compact.join(":")
24         end
25       end
26     end
27
28     # Returns the description for this task, with newlines collapsed and
29     # whitespace stripped. Returns the empty string if there is no
30     # description for this task.
31     def description(rebuild=false)
32       @description = nil if rebuild
33       @description ||= begin
34         description = @desc || ""
35
36         indentation = description[/\A\s+/]
37         if indentation
38           reformatted_description = ""
39           description.strip.each_line do |line|
40             line = line.chomp.sub(/^#{indentation}/, "")
41             line = line.gsub(/#{indentation}\s*/, " ") if line[/^\S/]
42             reformatted_description << line << "\n"
43           end
44           description = reformatted_description
45         end
46
47         description.strip.gsub(/\r\n/, "\n")
48       end
49     end
50
51     # Returns the first sentence of the full description. If +max_length+ is
52     # given, the result will be truncated if it is longer than +max_length+,
53     # and an ellipsis appended.
54     def brief_description(max_length=nil)
55       brief = description[/^.*?\.(?=\s|$)/] || description
56
57       if max_length && brief.length > max_length
58         brief = brief[0,max_length-3] + "..."
59       end
60
61       brief
62     end
63
64     # Indicates whether the task wants to continue, even if a server has failed
65     # previously
66     def continue_on_error?
67       @on_error == :continue
68     end
69   end
70 end
Note: See TracBrowser for help on using the browser.