Class: Capistrano::TaskDefinition
- Inherits:
-
Object
- Object
- Capistrano::TaskDefinition
- Defined in:
- lib/capistrano/task_definition.rb
Overview
Represents the definition of a single task.
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#desc ⇒ Object
readonly
Returns the value of attribute desc.
-
#max_hosts ⇒ Object
readonly
Returns the value of attribute max_hosts.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
-
#on_error ⇒ Object
readonly
Returns the value of attribute on_error.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#brief_description(max_length = nil) ⇒ Object
Returns the first sentence of the full description.
-
#continue_on_error? ⇒ Boolean
Indicates whether the task wants to continue, even if a server has failed previously.
-
#description(rebuild = false) ⇒ Object
Returns the description for this task, with newlines collapsed and whitespace stripped.
-
#fully_qualified_name ⇒ Object
Returns the task’s fully-qualified name, including the namespace.
-
#initialize(name, namespace, options = {}, &block) ⇒ TaskDefinition
constructor
A new instance of TaskDefinition.
Constructor Details
#initialize(name, namespace, options = {}, &block) ⇒ TaskDefinition
Returns a new instance of TaskDefinition.
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/capistrano/task_definition.rb', line 8 def initialize(name, namespace, ={}, &block) if name.to_s =~ /^(?:before_|after_)/ Kernel.warn("[Deprecation Warning] Naming tasks with before_ and after_ is deprecated, please see the new before() and after() methods. (Offending task name was #{name})") end @name, @namespace, @options = name, namespace, @desc = @options.delete(:desc) @on_error = .delete(:on_error) @max_hosts = [:max_hosts] && [:max_hosts].to_i @body = block or raise ArgumentError, "a task requires a block" @servers = nil end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
6 7 8 |
# File 'lib/capistrano/task_definition.rb', line 6 def body @body end |
#desc ⇒ Object (readonly)
Returns the value of attribute desc.
6 7 8 |
# File 'lib/capistrano/task_definition.rb', line 6 def desc @desc end |
#max_hosts ⇒ Object (readonly)
Returns the value of attribute max_hosts.
6 7 8 |
# File 'lib/capistrano/task_definition.rb', line 6 def max_hosts @max_hosts end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/capistrano/task_definition.rb', line 6 def name @name end |
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
6 7 8 |
# File 'lib/capistrano/task_definition.rb', line 6 def namespace @namespace end |
#on_error ⇒ Object (readonly)
Returns the value of attribute on_error.
6 7 8 |
# File 'lib/capistrano/task_definition.rb', line 6 def on_error @on_error end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/capistrano/task_definition.rb', line 6 def @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.
59 60 61 62 63 64 65 66 67 |
# File 'lib/capistrano/task_definition.rb', line 59 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
71 72 73 |
# File 'lib/capistrano/task_definition.rb', line 71 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.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/capistrano/task_definition.rb', line 36 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_name ⇒ Object
Returns the task’s fully-qualified name, including the namespace
23 24 25 26 27 28 29 30 31 |
# File 'lib/capistrano/task_definition.rb', line 23 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 |