| 1 |
require 'capistrano/server_definition' |
|---|
| 2 |
|
|---|
| 3 |
module Capistrano |
|---|
| 4 |
|
|---|
| 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 |
|
|---|
| 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 |
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 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(/^ |
|---|
| 41 |
line = line.gsub(/ |
|---|
| 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 |
|
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 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 |
|
|---|
| 65 |
|
|---|
| 66 |
def continue_on_error? |
|---|
| 67 |
@on_error == :continue |
|---|
| 68 |
end |
|---|
| 69 |
end |
|---|
| 70 |
end |
|---|