Class: Capistrano::TaskDefinition

Inherits:
Object
  • Object
show all
Defined in:
lib/capistrano/task_definition.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, namespace, options = {}, &block) ⇒ TaskDefinition

Returns a new instance of TaskDefinition.



9
10
11
12
13
14
15
16
# File 'lib/capistrano/task_definition.rb', line 9

def initialize(name, namespace, options={}, &block)
  @name, @namespace, @options = name, namespace, options
  @desc      = @options.delete(:desc)
  @on_error  = options.delete(:on_error)
  @max_hosts = options[:max_hosts] && options[:max_hosts].to_i
  @body      = block or raise ArgumentError, "a task requires a block"
  @servers   = nil
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



7
8
9
# File 'lib/capistrano/task_definition.rb', line 7

def body
  @body
end

#descObject (readonly)

Returns the value of attribute desc.



7
8
9
# File 'lib/capistrano/task_definition.rb', line 7

def desc
  @desc
end

#max_hostsObject (readonly)

Returns the value of attribute max_hosts.



7
8
9
# File 'lib/capistrano/task_definition.rb', line 7

def max_hosts
  @max_hosts
end

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/capistrano/task_definition.rb', line 7

def name
  @name
end

#namespaceObject (readonly)

Returns the value of attribute namespace.



7
8
9
# File 'lib/capistrano/task_definition.rb', line 7

def namespace
  @namespace
end

#on_errorObject (readonly)

Returns the value of attribute on_error.



7
8
9
# File 'lib/capistrano/task_definition.rb', line 7

def on_error
  @on_error
end

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/capistrano/task_definition.rb', line 7

def options
  @options
end

Instance Method Details

#brief_description(max_length = nil) ⇒ Object

Returns the first sentence of the full description. If max_length is given, the result will be truncated if it is longer than max_length, and an ellipsis appended.



60
61
62
63
64
65
66
67
68
# File 'lib/capistrano/task_definition.rb', line 60

def brief_description(max_length=nil)
  brief = description[/^.*?\.(?=\s|$)/] || description

  if max_length && brief.length > max_length
    brief = brief[0,max_length-3] + "..."
  end

  brief
end

#continue_on_error?Boolean

Indicates whether the task wants to continue, even if a server has failed previously

Returns:

  • (Boolean)


72
73
74
# File 'lib/capistrano/task_definition.rb', line 72

def continue_on_error?
  @on_error == :continue
end

#description(rebuild = false) ⇒ Object

Returns the description for this task, with newlines collapsed and whitespace stripped. Returns the empty string if there is no description for this task.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/capistrano/task_definition.rb', line 37

def description(rebuild=false)
  @description = nil if rebuild
  @description ||= begin
    description = @desc || ""

    indentation = description[/\A\s+/]
    if indentation
      reformatted_description = ""
      description.strip.each_line do |line|
        line = line.chomp.sub(/^#{indentation}/, "")
        line = line.gsub(/#{indentation}\s*/, " ") if line[/^\S/]
        reformatted_description << line << "\n"
      end
      description = reformatted_description
    end

    description.strip.gsub(/\r\n/, "\n")
  end
end

#fully_qualified_nameObject

Returns the task’s fully-qualified name, including the namespace



19
20
21
22
23
24
25
26
27
# File 'lib/capistrano/task_definition.rb', line 19

def fully_qualified_name
  @fully_qualified_name ||= begin
    if namespace.default_task == self
      namespace.fully_qualified_name
    else
      [namespace.fully_qualified_name, name].compact.join(":")
    end
  end
end