Class Index [+]

Quicksearch

Capistrano::Configuration::Namespaces

Constants

DEFAULT_TASK

Attributes

name[R]

The name of this namespace. Defaults to nil for the top-level namespace.

parent[R]

The parent namespace of this namespace. Returns nil for the top-level namespace.

tasks[R]

The hash of tasks defined for this namespace.

namespaces[R]

The hash of namespaces defined for this namespace.

Public Instance Methods

default_task() click to toggle source

Returns the default task for this namespace. This will be nil if the namespace is at the top-level, and will otherwise return the task named “default”. If no such task exists, nil will be returned.

     # File lib/capistrano/configuration/namespaces.rb, line 155
155:       def default_task
156:         return nil if parent.nil?
157:         return tasks[DEFAULT_TASK]
158:       end
define_task(task) click to toggle source
     # File lib/capistrano/configuration/namespaces.rb, line 106
106:       def define_task(task)
107:         tasks[task.name] = task
108: 
109:         metaclass = class << self; self; end
110:         metaclass.send(:define_method, task.name) { execute_task(tasks[task.name]) }
111:       end
desc(text) click to toggle source

Describe the next task to be defined. The given text will be attached to the next task that is defined and used as its description.

    # File lib/capistrano/configuration/namespaces.rb, line 50
50:       def desc(text)
51:         @next_description = text
52:       end
find_task(name) click to toggle source

Find the task with the given name, where name is the fully-qualified name of the task. This will search into the namespaces and return the referenced task, or nil if no such task can be found. If the name refers to a namespace, the task in that namespace named “default” will be returned instead, if one exists.

     # File lib/capistrano/configuration/namespaces.rb, line 118
118:       def find_task(name)
119:         parts = name.to_s.split(/:/)
120:         tail = parts.pop.to_sym
121: 
122:         ns = self
123:         until parts.empty?
124:           next_part = parts.shift
125:           ns = next_part.empty? ? nil : ns.namespaces[next_part.to_sym]
126:           return nil if ns.nil?
127:         end
128: 
129:         if ns.namespaces.key?(tail)
130:           ns = ns.namespaces[tail]
131:           tail = DEFAULT_TASK
132:         end
133: 
134:         ns.tasks[tail]
135:       end
fully_qualified_name() click to toggle source

Returns the fully-qualified name of this namespace, or nil if the namespace is at the top-level.

    # File lib/capistrano/configuration/namespaces.rb, line 43
43:       def fully_qualified_name
44:         return nil if name.nil?
45:         [parent.fully_qualified_name, name].compact.join(":")
46:       end
namespace(name, &block) click to toggle source

Open a namespace in which to define new tasks. If the namespace was defined previously, it will be reopened, otherwise a new namespace will be created for the given name.

    # File lib/capistrano/configuration/namespaces.rb, line 65
65:       def namespace(name, &block)
66:         name = name.to_sym
67:         raise ArgumentError, "expected a block" unless block_given?
68: 
69:         namespace_already_defined = namespaces.key?(name)
70:         if all_methods.any? { |m| m.to_sym == name } && !namespace_already_defined
71:           thing = tasks.key?(name) ? "task" : "method"
72:           raise ArgumentError, "defining a namespace named `#{name}' would shadow an existing #{thing} with that name"
73:         end
74: 
75:         namespaces[name] ||= Namespace.new(name, self)
76:         namespaces[name].instance_eval(&block)
77: 
78:         # make sure any open description gets terminated
79:         namespaces[name].desc(nil)
80: 
81:         if !namespace_already_defined
82:           metaclass = class << self; self; end
83:           metaclass.send(:define_method, name) { namespaces[name] }
84:         end
85:       end
next_description(reset=false) click to toggle source

Returns the value set by the last, pending “desc” call. If reset is not false, the value will be reset immediately afterwards.

    # File lib/capistrano/configuration/namespaces.rb, line 56
56:       def next_description(reset=false)
57:         @next_description
58:       ensure
59:         @next_description = nil if reset
60:       end
search_task(name) click to toggle source

Given a task name, this will search the current namespace, and all parent namespaces, looking for a task that matches the name, exactly. It returns the task, if found, or nil, if not.

     # File lib/capistrano/configuration/namespaces.rb, line 140
140:       def search_task(name)
141:         name = name.to_sym
142:         ns = self
143: 
144:         until ns.nil?
145:           return ns.tasks[name] if ns.tasks.key?(name)
146:           ns = ns.parent
147:         end
148: 
149:         return nil
150:       end
task(name, options={}, &block) click to toggle source

Describe a new task. If a description is active (see #), it is added to the options under the :desc key. The new task is added to the namespace.

     # File lib/capistrano/configuration/namespaces.rb, line 90
 90:       def task(name, options={}, &block)
 91:         name = name.to_sym
 92:         raise ArgumentError, "expected a block" unless block_given?
 93: 
 94:         task_already_defined = tasks.key?(name)
 95:         if all_methods.any? { |m| m.to_sym == name } && !task_already_defined
 96:           thing = namespaces.key?(name) ? "namespace" : "method"
 97:           raise ArgumentError, "defining a task named `#{name}' would shadow an existing #{thing} with that name"
 98:         end
 99: 
100: 
101:         task = TaskDefinition.new(name, self, {:desc => next_description(:reset)}.merge(options), &block)
102: 
103:         define_task(task)
104:       end
task_list(all=false) click to toggle source

Returns the tasks in this namespace as an array of TaskDefinition objects. If a non-false parameter is given, all tasks in all namespaces under this namespace will be returned as well.

     # File lib/capistrano/configuration/namespaces.rb, line 163
163:       def task_list(all=false)
164:         list = tasks.values
165:         namespaces.each { |name,space| list.concat(space.task_list(:all)) } if all
166:         list
167:       end
top() click to toggle source

Returns the top-level namespace (the one with no parent).

    # File lib/capistrano/configuration/namespaces.rb, line 36
36:       def top
37:         return parent.top if parent
38:         return self
39:       end

Private Instance Methods

all_methods() click to toggle source
     # File lib/capistrano/configuration/namespaces.rb, line 171
171:         def all_methods
172:           public_methods.concat(protected_methods).concat(private_methods)
173:         end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.