class Aruba::Platforms::UnixEnvironmentVariables
Abstract environment variables
Constants
- UNDEFINED
-
We need to use this, because ‘nil` is a valid value as default
Attributes
Public Class Methods
Source
# File lib/aruba/platforms/unix_environment_variables.rb, line 196 def self.hash_from_env ENV.to_hash end
Source
# File lib/aruba/platforms/unix_environment_variables.rb, line 52 def initialize(env = ENV) @actions = [] @env = env.to_h end
Public Instance Methods
Source
# File lib/aruba/platforms/unix_environment_variables.rb, line 98 def [](name) to_h[name.to_s] end
Get value of variable
@param [#to_s] name
The name of the variable
Source
# File lib/aruba/platforms/unix_environment_variables.rb, line 109 def []=(name, value) value = value.to_s actions << UpdateAction.new(name.to_s => value) end
Set value of variable
@param [#to_s] name
The name of the variable
@param [#to_s] value
The value of the variable
Source
# File lib/aruba/platforms/unix_environment_variables.rb, line 122 def append(name, value) name = name.to_s value = self[name].to_s + value.to_s actions << UpdateAction.new(name => value) value end
Append value to variable
@param [#to_s] name
The name of the variable
@param [#to_s] value
The value of the variable
Source
# File lib/aruba/platforms/unix_environment_variables.rb, line 181 def clear value = to_h actions.clear value end
Reset environment
Source
# File lib/aruba/platforms/unix_environment_variables.rb, line 151 def delete(name) # Rescue value, before it is deleted value = to_h[name.to_s] actions << RemoveAction.new(name.to_s) value end
Delete variable
@param [#to_s] name
The name of the variable
Source
# File lib/aruba/platforms/unix_environment_variables.rb, line 78 def fetch(name, default = UNDEFINED) if default == UNDEFINED to_h.fetch name.to_s else to_h.fetch name.to_s, default end end
Fetch variable from environment
@param [#to_s] name
The name of the variable
@param [Object] default
The default value used, if the variable is not defined
Source
# File lib/aruba/platforms/unix_environment_variables.rb, line 90 def key?(name) to_h.key? name.to_s end
Check if variable exist
@param [#to_s] name
The name of the variable
Source
# File lib/aruba/platforms/unix_environment_variables.rb, line 161 def method_missing(name, ...) super unless to_h.respond_to? name to_h.send(name, ...) end
Pass on checks
Calls superclass method
Source
# File lib/aruba/platforms/unix_environment_variables.rb, line 189 def nest old_actions = @actions.dup yield(self) ensure @actions = old_actions end
Source
# File lib/aruba/platforms/unix_environment_variables.rb, line 138 def prepend(name, value) name = name.to_s value = value.to_s + self[name].to_s actions << UpdateAction.new(name => value) value end
Prepend value to variable
@param [#to_s] name
The name of the variable
@param [#to_s] value
The value of the variable
Source
# File lib/aruba/platforms/unix_environment_variables.rb, line 168 def respond_to_missing?(name, _private) to_h.respond_to? name end
Check for respond_to
Source
# File lib/aruba/platforms/unix_environment_variables.rb, line 176 def to_h actions.inject(hash_from_env.merge(env)) { |a, e| e.call(a) } end
Convert to hash
@return [Hash]
A new hash from environment
Source
# File lib/aruba/platforms/unix_environment_variables.rb, line 65 def update(other_env) actions << UpdateAction.new(other_env) self end
Update environment with other en
@param [#to_hash, to_h
] other_env
Another environment object or hash
@yield
Pass block to env
Private Instance Methods
Source
# File lib/aruba/platforms/unix_environment_variables.rb, line 202 def hash_from_env self.class.hash_from_env end