Module: Capistrano::Configuration::Variables

### Home Classes Methods

### In Files

- lib/capistrano/configuration/variables.rb

### Methods

- #[]
- #[]=
- #exists?
- #fetch
- #reset!
- #set
- #unset

### 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::Variables

### Attributes

variables[R]

The hash of variables that have been defined in this configuration instance.

### Public Instance Methods

[](variable) click to toggle source

    # File lib/capistrano/configuration/variables.rb, line 94
    def [](variable)
      fetch(variable, nil)
    end

[]=(variable, *args, &block) click to toggle source
Alias for: set
exists?(variable) click to toggle source

Returns true if the variable has been defined, and false otherwise.

    # File lib/capistrano/configuration/variables.rb, line 50
    def exists?(variable)
      @variables.key?(variable.to_sym)
    end

fetch(variable, *args) click to toggle source

Access a named variable. If the value of the variable responds_to? :call, call will be invoked (without parameters) and the return value cached and returned.

    # File lib/capistrano/configuration/variables.rb, line 72
    def fetch(variable, *args)
      if !args.empty? && block_given?
        raise ArgumentError, "you must specify either a default value or a block, but not both"
      end

      sym = variable.to_sym
      protect(sym) do
        if !@variables.key?(sym)
          return args.first unless args.empty?
          return yield(variable) if block_given?
          raise IndexError, "`#{variable}' not found"
        end

        if @variables[sym].respond_to?(:call)
          @original_procs[sym] = @variables[sym]
          @variables[sym] = @variables[sym].call
        end
      end

      @variables[sym]
    end

reset!(variable) click to toggle source

If the variable was originally a proc value, it will be reset to it's original proc value. Otherwise, this method does nothing. It returns true if the variable was actually reset.

    # File lib/capistrano/configuration/variables.rb, line 57
    def reset!(variable)
      sym = variable.to_sym
      protect(sym) do
        if @original_procs.key?(sym)
          @variables[sym] = @original_procs.delete(sym)
          true
        else
          false
        end
      end
    end

set(variable, *args, &block) click to toggle source

Set a variable to the given value.

    # File lib/capistrano/configuration/variables.rb, line 20
    def set(variable, *args, &block)
      if variable.to_s !~ /^[_a-z]/
        raise ArgumentError, "invalid variable `#{variable}' (variables must begin with an underscore, or a lower-case letter)"
      end

      if !block_given? && args.empty? || block_given? && !args.empty?
        raise ArgumentError, "you must specify exactly one of either a value or a block"
      end

      if args.length > 1
        raise ArgumentError, "wrong number of arguments (#{args.length} for 1)"
      end

      value = args.empty? ? block : args.first
      sym = variable.to_sym
      protect(sym) { @variables[sym] = value }
    end

Also aliased as: []=
unset(variable) click to toggle source

Removes any trace of the given variable.

    # File lib/capistrano/configuration/variables.rb, line 41
    def unset(variable)
      sym = variable.to_sym
      protect(sym) do
        @original_procs.delete(sym)
        @variables.delete(sym)
      end
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.