Module Capistrano::Configuration::Variables
In: lib/capistrano/configuration/variables.rb
lib/capistrano/configuration/variables.rb

Methods

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

Attributes

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

Public Instance methods

[Source]

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

[Source]

    # File lib/capistrano/configuration/variables.rb, line 94
94:       def [](variable)
95:         fetch(variable, nil)
96:       end
[]=(variable, *args, &block)

Alias for set

[]=(variable, *args, &block)

Alias for set

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

[Source]

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

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

[Source]

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

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.

[Source]

    # File lib/capistrano/configuration/variables.rb, line 72
72:       def fetch(variable, *args)
73:         if !args.empty? && block_given?
74:           raise ArgumentError, "you must specify either a default value or a block, but not both"
75:         end
76: 
77:         sym = variable.to_sym
78:         protect(sym) do
79:           if !@variables.key?(sym)
80:             return args.first unless args.empty?
81:             return yield(variable) if block_given?
82:             raise IndexError, "`#{variable}' not found"
83:           end
84: 
85:           if @variables[sym].respond_to?(:call)
86:             @original_procs[sym] = @variables[sym]
87:             @variables[sym] = @variables[sym].call
88:           end
89:         end
90: 
91:         @variables[sym]
92:       end

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.

[Source]

    # File lib/capistrano/configuration/variables.rb, line 72
72:       def fetch(variable, *args)
73:         if !args.empty? && block_given?
74:           raise ArgumentError, "you must specify either a default value or a block, but not both"
75:         end
76: 
77:         sym = variable.to_sym
78:         protect(sym) do
79:           if !@variables.key?(sym)
80:             return args.first unless args.empty?
81:             return yield(variable) if block_given?
82:             raise IndexError, "`#{variable}' not found"
83:           end
84: 
85:           if @variables[sym].respond_to?(:call)
86:             @original_procs[sym] = @variables[sym]
87:             @variables[sym] = @variables[sym].call
88:           end
89:         end
90: 
91:         @variables[sym]
92:       end

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.

[Source]

    # File lib/capistrano/configuration/variables.rb, line 57
57:       def reset!(variable)
58:         sym = variable.to_sym
59:         protect(sym) do
60:           if @original_procs.key?(sym)
61:             @variables[sym] = @original_procs.delete(sym)
62:             true
63:           else
64:             false
65:           end
66:         end
67:       end

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.

[Source]

    # File lib/capistrano/configuration/variables.rb, line 57
57:       def reset!(variable)
58:         sym = variable.to_sym
59:         protect(sym) do
60:           if @original_procs.key?(sym)
61:             @variables[sym] = @original_procs.delete(sym)
62:             true
63:           else
64:             false
65:           end
66:         end
67:       end

Set a variable to the given value.

[Source]

    # File lib/capistrano/configuration/variables.rb, line 20
20:       def set(variable, *args, &block)
21:         if variable.to_s !~ /^[_a-z]/
22:           raise ArgumentError, "invalid variable `#{variable}' (variables must begin with an underscore, or a lower-case letter)"
23:         end
24: 
25:         if !block_given? && args.empty? || block_given? && !args.empty?
26:           raise ArgumentError, "you must specify exactly one of either a value or a block"
27:         end
28: 
29:         if args.length > 1
30:           raise ArgumentError, "wrong number of arguments (#{args.length} for 1)"
31:         end
32: 
33:         value = args.empty? ? block : args.first
34:         sym = variable.to_sym
35:         protect(sym) { @variables[sym] = value }
36:       end

Set a variable to the given value.

[Source]

    # File lib/capistrano/configuration/variables.rb, line 20
20:       def set(variable, *args, &block)
21:         if variable.to_s !~ /^[_a-z]/
22:           raise ArgumentError, "invalid variable `#{variable}' (variables must begin with an underscore, or a lower-case letter)"
23:         end
24: 
25:         if !block_given? && args.empty? || block_given? && !args.empty?
26:           raise ArgumentError, "you must specify exactly one of either a value or a block"
27:         end
28: 
29:         if args.length > 1
30:           raise ArgumentError, "wrong number of arguments (#{args.length} for 1)"
31:         end
32: 
33:         value = args.empty? ? block : args.first
34:         sym = variable.to_sym
35:         protect(sym) { @variables[sym] = value }
36:       end

Removes any trace of the given variable.

[Source]

    # File lib/capistrano/configuration/variables.rb, line 41
41:       def unset(variable)
42:         sym = variable.to_sym
43:         protect(sym) do
44:           @original_procs.delete(sym)
45:           @variables.delete(sym)
46:         end
47:       end

Removes any trace of the given variable.

[Source]

    # File lib/capistrano/configuration/variables.rb, line 41
41:       def unset(variable)
42:         sym = variable.to_sym
43:         protect(sym) do
44:           @original_procs.delete(sym)
45:           @variables.delete(sym)
46:         end
47:       end

[Validate]