Class: Aruba::Platforms::WindowsEnvironmentVariables
- Inherits:
-
UnixEnvironmentVariables
- Object
- UnixEnvironmentVariables
- Aruba::Platforms::WindowsEnvironmentVariables
- Defined in:
- lib/aruba/platforms/windows_environment_variables.rb
Overview
Windows is case-insensitive when it accesses its environment variables. That means that at the Windows command line:
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;
If you access environment variables through ENV, you can access values no matter the case of the key:
irb: > ENV["Path"] => ".;.\bin;c:\rubys\ruby-2.1.6-p336\bin;" irb: > ENV["Path"] => ".;.\bin;c:\rubys\ruby-2.1.6-p336\bin;"
But if you copy the ENV to a hash, Ruby treats the keys as case sensitive:
irb: > env_copy = ENV.to_hash => "ANSICON"=>"119x1000 (119x58)", "ANSICON_DEF"=>"7", APPDATA"=>"C:\Users\blorf\AppData\Roaming", .... irb: > env["Path"] => ".;.\bin;c:\rubys\ruby-2.1.6-p336\bin;" irb: > env["PATH"] => nil
Thus 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.
Constant Summary
Constants inherited from UnixEnvironmentVariables
UnixEnvironmentVariables::UNDEFINED
Instance Method Summary collapse
- #[](name) ⇒ Object
- #[]=(name, value) ⇒ Object
- #append(name, value) ⇒ Object
- #delete(name, value) ⇒ Object
- #fetch(name, default = UnixEnvironmentVariables::UNDEFINED) ⇒ Object
-
#initialize(env = ENV.to_hash) ⇒ WindowsEnvironmentVariables
constructor
A new instance of WindowsEnvironmentVariables.
- #key?(name) ⇒ Boolean
- #prepend(name, value) ⇒ Object
- #update(other_env, &block) ⇒ Object
Methods inherited from UnixEnvironmentVariables
#clear, #method_missing, #respond_to_missing?, #to_h
Constructor Details
#initialize(env = ENV.to_hash) ⇒ WindowsEnvironmentVariables
Returns a new instance of WindowsEnvironmentVariables.
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/aruba/platforms/windows_environment_variables.rb', line 36 def initialize(env = ENV.to_hash) @actions = [] @env = if RUBY_VERSION <= '1.9.3' # rubocop:disable Style/EachWithObject env.inject({}) { |a, (k,v)| a[k.to_s.upcase] = v; a } # rubocop:enable Style/EachWithObject else env.each_with_object({}) { |(k,v), a| a[k.to_s.upcase] = v } end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Aruba::Platforms::UnixEnvironmentVariables
Instance Method Details
#[](name) ⇒ Object
68 69 70 |
# File 'lib/aruba/platforms/windows_environment_variables.rb', line 68 def [](name) super(name.upcase) end |
#[]=(name, value) ⇒ Object
72 73 74 |
# File 'lib/aruba/platforms/windows_environment_variables.rb', line 72 def []=(name, value) super(name.upcase, value) end |
#append(name, value) ⇒ Object
76 77 78 |
# File 'lib/aruba/platforms/windows_environment_variables.rb', line 76 def append(name, value) super(name.upcase, value) end |
#delete(name, value) ⇒ Object
84 85 86 |
# File 'lib/aruba/platforms/windows_environment_variables.rb', line 84 def delete(name, value) super(name.upcase, value) end |
#fetch(name, default = UnixEnvironmentVariables::UNDEFINED) ⇒ Object
60 61 62 |
# File 'lib/aruba/platforms/windows_environment_variables.rb', line 60 def fetch(name, default = UnixEnvironmentVariables::UNDEFINED) super(name.upcase, default) end |
#key?(name) ⇒ Boolean
64 65 66 |
# File 'lib/aruba/platforms/windows_environment_variables.rb', line 64 def key?(name) super(name.upcase) end |
#prepend(name, value) ⇒ Object
80 81 82 |
# File 'lib/aruba/platforms/windows_environment_variables.rb', line 80 def prepend(name, value) super(name.upcase, value) end |
#update(other_env, &block) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/aruba/platforms/windows_environment_variables.rb', line 48 def update(other_env, &block) other_env = if RUBY_VERSION <= '1.9.3' # rubocop:disable Style/EachWithObject other_env.inject({}) { |a, (k,v)| a[k.to_s.upcase] = v; a } # rubocop:enable Style/EachWithObject else other_env.each_with_object({}) { |(k,v), a| a[k.to_s.upcase] = v } end super(other_env, &block) end |