Module: Env
- Defined in:
- lib/GGEnv.rb
Overview
Env
Documentation
This file contains auxiliary routines to easily interact with environment variables that contain lists of paths, like PATH, LD_LIBRARY_PATH, MAYA_SCRIPT_PATH, etc.
Usage
Env.check_directories = false # turn off verification that
# directories exist (default: true)
path = Env['PATH']
path << "C:/newpath" # As path is modified, so
# is ENV['PATH']
path.delete_if { |x| x =~ /maya/ } # remove all paths that have maya
path.unshift ["C:/", "E:/bin"] # add these paths at start
Env['PATH'] = path[0,2] + path[4,6] # concat two slices and send to PATH
path.check_directories # check existance of directories
# for this variable only (unlike
# Env.check_directories)
Defined Under Namespace
Classes: EnvVar
Class Method Summary collapse
-
.[](a) ⇒ Object
Access an environment variable as an array.
-
.[]=(a, b) ⇒ Object
Assign a new value (Array or String) to an environment variable.
-
.check_directories=(a) ⇒ Object
If true, check directories of all Env variables automatically.
-
.check_directories? ⇒ Boolean
Are we checking directories of all variables automatically?.
-
.clear ⇒ Object
Clear the Env path cache to free some memory.
Class Method Details
.[](a) ⇒ Object
91 92 93 94 |
# File 'lib/GGEnv.rb', line 91 def self.[](a) return @@_envvars[a] if @@_envvars[a] @@_envvars[a] = EnvVar.new( a, ENV[a] ) end |
.[]=(a, b) ⇒ Object
Assign a new value (Array or String) to an environment variable.
Example
Env['PATH'] = ['/usr/', '/usr/local/']
75 76 77 |
# File 'lib/GGEnv.rb', line 75 def self.[]=(a, b) @@_envvars[a] = EnvVar.new( a, b ) end |
.check_directories=(a) ⇒ Object
116 117 118 119 120 121 |
# File 'lib/GGEnv.rb', line 116 def self.check_directories=(a) @@_check_dirs = (a == true) if @@_check_dirs @@_envvars.each_value { |v| v.check_directories } end end |
.check_directories? ⇒ Boolean
Are we checking directories of all variables automatically?
99 100 101 |
# File 'lib/GGEnv.rb', line 99 def self.check_directories? @@_check_dirs end |