class Capistrano::EnvConfig::Environment
Constants
- BLANK_RE
Public Class Methods
new( roles = fetch( :env_config_roles ) )
click to toggle source
# File lib/capistrano/env_config/environment.rb, line 7 def initialize( roles = fetch( :env_config_roles ) ) variables = { } # Acquire all configuration variables and store them in a dictionary (hash) on roles( roles ) do output = capture( 'cat /etc/environment' ) output.each_line do |line| captures = line.match( /\s*([A-Z_][A-Z0-9_]*)=(.*)/ ) if captures&.length == 3 variables[ captures[1] ] = captures[2] end end end @variables = variables end
Public Instance Methods
delete( key )
click to toggle source
# File lib/capistrano/env_config/environment.rb, line 38 def delete( key ) raise KeyNotSpecified.new if BLANK_RE === key @variables.delete( key.to_s.upcase ) end
get( key )
click to toggle source
# File lib/capistrano/env_config/environment.rb, line 24 def get( key ) raise KeyNotSpecified.new if BLANK_RE === key return @variables[ key.to_s.upcase ] end
list()
click to toggle source
# File lib/capistrano/env_config/environment.rb, line 29 def list @variables end
set( key, value )
click to toggle source
# File lib/capistrano/env_config/environment.rb, line 33 def set( key, value ) raise KeyNotSpecified.new if BLANK_RE === key @variables[ key.to_s.upcase ] = value.to_s end
sync( roles = fetch( :env_config_roles ) )
click to toggle source
# File lib/capistrano/env_config/environment.rb, line 43 def sync( roles = fetch( :env_config_roles ) ) # Concatenate all variables and output them in the appropariate format environment = '' @variables.each do |key, value| environment += "#{key.upcase}=#{value}\n" end # Upload the variables to all servers on roles( roles ) do contents = StringIO.new( environment, 'r' ) upload! contents, '/etc/environment' end end