Module: Capistrano::Configuration::Namespaces

### Home Classes Methods

### In Files

- lib/capistrano/configuration/namespaces.rb

### Namespace

- CLASS Capistrano::Configuration::Namespaces::Namespace

### Methods

- #default_task
- #define_task
- #desc
- #find_task
- #fully_qualified_name
- #namespace
- #next_description
- #search_task
- #task
- #task_list
- #top

### Files

- help.txt

### Class/Module Index

Quicksearch

- Capistrano
- Capistrano::CLI
- Capistrano::CLI::Execute
- Capistrano::CLI::Execute::ClassMethods
- Capistrano::CLI::Help
- Capistrano::CLI::Options
- Capistrano::CLI::Options::ClassMethods
- Capistrano::CLI::UI
- Capistrano::CLI::UI::ClassMethods
- Capistrano::Callback
- Capistrano::Command
- Capistrano::Command::Tree
- Capistrano::Command::Tree::Branch
- Capistrano::Command::Tree::ConditionBranch
- Capistrano::Command::Tree::ConditionBranch::Evaluator
- Capistrano::Command::Tree::ElseBranch
- Capistrano::Configuration
- Capistrano::Configuration::Actions
- Capistrano::Configuration::Actions::FileTransfer
- Capistrano::Configuration::Actions::Inspect
- Capistrano::Configuration::Actions::Invocation
- Capistrano::Configuration::Actions::Invocation::ClassMethods
- Capistrano::Configuration::AliasTask
- Capistrano::Configuration::Callbacks
- Capistrano::Configuration::Connections
- Capistrano::Configuration::Execution
- Capistrano::Configuration::Loading
- Capistrano::Configuration::Loading::ClassMethods
- Capistrano::Configuration::LogFormatters
- Capistrano::Configuration::Namespaces
- Capistrano::Configuration::Namespaces::Namespace
- Capistrano::Configuration::Roles
- Capistrano::Configuration::Servers
- Capistrano::Configuration::Variables
- Capistrano::Deploy
- Capistrano::Deploy::Dependencies
- Capistrano::Deploy::LocalDependency
- Capistrano::Deploy::RemoteDependency
- Capistrano::Deploy::SCM
- Capistrano::Deploy::SCM::Accurev
- Capistrano::Deploy::SCM::Accurev::InternalRevision
- Capistrano::Deploy::SCM::Base
- Capistrano::Deploy::SCM::Base::LocalProxy
- Capistrano::Deploy::SCM::Bzr
- Capistrano::Deploy::SCM::Cvs
- Capistrano::Deploy::SCM::Darcs
- Capistrano::Deploy::SCM::Git
- Capistrano::Deploy::SCM::Mercurial
- Capistrano::Deploy::SCM::None
- Capistrano::Deploy::SCM::Perforce
- Capistrano::Deploy::SCM::Subversion
- Capistrano::Deploy::Strategy
- Capistrano::Deploy::Strategy::Base
- Capistrano::Deploy::Strategy::Checkout
- Capistrano::Deploy::Strategy::Copy
- Capistrano::Deploy::Strategy::Export
- Capistrano::Deploy::Strategy::Remote
- Capistrano::Deploy::Strategy::RemoteCache
- Capistrano::Deploy::Strategy::UnsharedRemoteCache
- Capistrano::ProcCallback
- Capistrano::Processable
- Capistrano::Processable::SessionAssociation
- Capistrano::RemoteError
- Capistrano::Role
- Capistrano::Role::DynamicServerList
- Capistrano::SSH
- Capistrano::ServerDefinition
- Capistrano::Shell
- Capistrano::TaskCallback
- Capistrano::TaskDefinition
- Capistrano::Transfer
- Capistrano::Transfer::SFTPTransferWrapper
- Capistrano::Version
- Kernel
- Object
- String

No matching classes.

# Capistrano::Configuration::Namespaces

### Constants

DEFAULT_TASK

### Attributes

name[R]

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

namespaces[R]

The hash of namespaces defined for this 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.

### 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
    def default_task
      return nil if parent.nil?
      return tasks[DEFAULT_TASK]
    end

define_task(task) click to toggle source

    # File lib/capistrano/configuration/namespaces.rb, line 106
    def define_task(task)
      tasks[task.name] = task

      metaclass = class << self; self; end
      metaclass.send(:define_method, task.name) { execute_task(tasks[task.name]) }
    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
    def desc(text)
      @next_description = text
    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
    def find_task(name)
      parts = name.to_s.split(/:/)
      tail = parts.pop.to_sym

      ns = self
      until parts.empty?
        next_part = parts.shift
        ns = next_part.empty? ? nil : ns.namespaces[next_part.to_sym]
        return nil if ns.nil?
      end

      if ns.namespaces.key?(tail)
        ns = ns.namespaces[tail]
        tail = DEFAULT_TASK
      end

      ns.tasks[tail]
    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
    def fully_qualified_name
      return nil if name.nil?
      [parent.fully_qualified_name, name].compact.join(":")
    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
    def namespace(name, &block)
      name = name.to_sym
      raise ArgumentError, "expected a block" unless block_given?

      namespace_already_defined = namespaces.key?(name)
      if all_methods.any? { |m| m.to_sym == name } && !namespace_already_defined
        thing = tasks.key?(name) ? "task" : "method"
        raise ArgumentError, "defining a namespace named `#{name}' would shadow an existing #{thing} with that name"
      end

      namespaces[name] ||= Namespace.new(name, self)
      namespaces[name].instance_eval(&block)

      # make sure any open description gets terminated
      namespaces[name].desc(nil)

      if !namespace_already_defined
        metaclass = class << self; self; end
        metaclass.send(:define_method, name) { namespaces[name] }
      end
    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
    def next_description(reset=false)
      @next_description
    ensure
      @next_description = nil if reset
    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
    def search_task(name)
      name = name.to_sym
      ns = self

      until ns.nil?
        return ns.tasks[name] if ns.tasks.key?(name)
        ns = ns.parent
      end

      return nil
    end

task(name, options={}, &block) click to toggle source

Describe a new task. If a description is active (see desc), 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
    def task(name, options={}, &block)
      name = name.to_sym
      raise ArgumentError, "expected a block" unless block_given?

      task_already_defined = tasks.key?(name)
      if all_methods.any? { |m| m.to_sym == name } && !task_already_defined
        thing = namespaces.key?(name) ? "namespace" : "method"
        raise ArgumentError, "defining a task named `#{name}' would shadow an existing #{thing} with that name"
      end

      task = TaskDefinition.new(name, self, {:desc => next_description(:reset)}.merge(options), &block)

      define_task(task)
    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
    def task_list(all=false)
      list = tasks.values
      namespaces.each { |name,space| list.concat(space.task_list(:all)) } if all
      list
    end

top() click to toggle source

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

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

[Validate]

Generated with the Darkfish Rdoc Generator 2.