class Aruba::Platforms::WindowsEnvironmentVariables

Windows is case-insensitive when it accesses its environment variables.

To work around this we turn all of the environment variable keys to upper-case so that aruba is ensured that accessing environment variables with upper-case keys will always work. See the following examples.

@example Setting Windows environment variables using mixed case

C:>set Path
C:>Path=.;.\bin;c:\rubys\ruby-2.1.6-p336\bin;
C:>set PATH
C:>Path=.;.\bin;c:\rubys\ruby-2.1.6-p336\bin;

@example If you access environment variables through ENV, you can access values no matter the case of the key:

ENV["Path"] # => ".;.\bin;c:\rubys\ruby-2.1.6-p336\bin;"
ENV["PATH"] # => ".;.\bin;c:\rubys\ruby-2.1.6-p336\bin;"

@example But if you copy the ENV to a hash, Ruby treats the keys as case sensitive:

env_copy = ENV.to_hash
# => {
"ALLUSERSPROFILE"=>
  "C:\\ProgramData",
  "ANSICON"=>"119x1000 (119x58)",
  "ANSICON_DEF"=>"7",
  APPDATA" => "C:\\Users\\blorf\\AppData\\Roaming", ....
}
env["Path"]
# => ".;.\bin;c:\rubys\ruby-2.1.6-p336\bin;"
env["PATH"]
# => nil

Public Class Methods

hash_from_env() click to toggle source
# File lib/aruba/platforms/windows_environment_variables.rb, line 74
def self.hash_from_env
  upcase_env(ENV)
end
new(env = ENV) click to toggle source
# File lib/aruba/platforms/windows_environment_variables.rb, line 38
def initialize(env = ENV)
  super(upcase_env env)
end
upcase_env(env) click to toggle source
# File lib/aruba/platforms/windows_environment_variables.rb, line 78
def self.upcase_env(env)
  env.to_h.transform_keys { |k| k.to_s.upcase }
end

Public Instance Methods

[](name) click to toggle source
# File lib/aruba/platforms/windows_environment_variables.rb, line 54
def [](name)
  super(name.upcase)
end
[]=(name, value) click to toggle source
# File lib/aruba/platforms/windows_environment_variables.rb, line 58
def []=(name, value)
  super(name.upcase, value)
end
append(name, value) click to toggle source
# File lib/aruba/platforms/windows_environment_variables.rb, line 62
def append(name, value)
  super(name.upcase, value)
end
delete(name) click to toggle source
# File lib/aruba/platforms/windows_environment_variables.rb, line 70
def delete(name)
  super(name.upcase)
end
fetch(name, default = UnixEnvironmentVariables::UNDEFINED) click to toggle source
# File lib/aruba/platforms/windows_environment_variables.rb, line 46
def fetch(name, default = UnixEnvironmentVariables::UNDEFINED)
  super(name.upcase, default)
end
key?(name) click to toggle source
# File lib/aruba/platforms/windows_environment_variables.rb, line 50
def key?(name)
  super(name.upcase)
end
prepend(name, value) click to toggle source
# File lib/aruba/platforms/windows_environment_variables.rb, line 66
def prepend(name, value)
  super(name.upcase, value)
end
update(other_env, &block) click to toggle source
# File lib/aruba/platforms/windows_environment_variables.rb, line 42
def update(other_env, &block)
  super(upcase_env(other_env), &block)
end

Private Instance Methods

upcase_env(env) click to toggle source
# File lib/aruba/platforms/windows_environment_variables.rb, line 84
def upcase_env(env)
  self.class.upcase_env(env)
end