Class: EnvVar
- Inherits:
-
RumoduleCommon
- Object
- RumoduleCommon
- EnvVar
- Defined in:
- bin/rumodule
Overview
Environment variable that has been read from “unix” env.
Constant Summary
Constant Summary
Constants inherited from RumoduleCommon
Instance Attribute Summary (collapse)
-
- (Object) dirty
readonly
Dirty flag indicates that the env has to be updated.
-
- (Object) name
readonly
Variable name.
-
- (Object) value
readonly
EnvVar value.
Class Method Summary (collapse)
-
+ (String) exist?(name)
Check for “unix” var existance.
Instance Method Summary (collapse)
-
- (Object) append_path(value)
Place new value at end of the path.
-
- (Object) delete_index(idx)
Remove value at index.
-
- (String) export
Format EnvVar for shell.
-
- (EnvVar) initialize(name, value = nil)
constructor
Initialize name, dirty and unset.
-
- (Integer) length
Entries in Env var.
-
- (Object) prepend_path(value)
Place new value infront of the path.
-
- (Object) remove_path(value)
Remove value from the path.
-
- (Object) set(value)
Set variable to a value.
-
- (Object) unset
Unset variable from env.
Methods included from RumoduleMod
Constructor Details
- (EnvVar) initialize(name, value = nil)
Initialize name, dirty and unset. If unset is true, then “unset” command is output to shell.
317 318 319 320 321 322 323 324 325 326 |
# File 'bin/rumodule', line 317 def initialize( name, value = nil ) @name = name @dirty = false @unset = false if value @value = value else @value = ENV[name].split(':') end end |
Instance Attribute Details
- (Object) dirty (readonly)
Dirty flag indicates that the env has to be updated.
297 298 299 |
# File 'bin/rumodule', line 297 def dirty @dirty end |
- (Object) name (readonly)
Variable name.
294 295 296 |
# File 'bin/rumodule', line 294 def name @name end |
- (Object) value (readonly)
EnvVar value.
300 301 302 |
# File 'bin/rumodule', line 300 def value @value end |
Class Method Details
+ (String) exist?(name)
Check for “unix” var existance.
307 308 309 |
# File 'bin/rumodule', line 307 def EnvVar.exist?( name ) ENV[name] end |
Instance Method Details
- (Object) append_path(value)
Place new value at end of the path.
360 361 362 363 364 |
# File 'bin/rumodule', line 360 def append_path( value ) @dirty = true @unset = false @value.push( value ) end |
- (Object) delete_index(idx)
Remove value at index.
380 381 382 383 384 |
# File 'bin/rumodule', line 380 def delete_index( idx ) @dirty = true @unset = false @value.delete_at( idx ) end |
- (String) export
Format EnvVar for shell. Output depends on whether the EnvVar has been “unset” or not.
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 |
# File 'bin/rumodule', line 399 def export if @unset case SHELL when 'zsh', 'sh', 'bash'; "unset #{name}" when 'fish'; "set -e #{name}" else raise "Unknown shell: \"#{SHELL}\"" end else case SHELL when 'zsh', 'sh', 'bash'; "export #{name}=#{@value.join(':')}" when 'fish'; if name == 'PATH' "set -gx #{name} #{@value.join(' ')}" else "set -gx #{name} #{@value.join(':')}" end else raise "Unknown shell: \"#{SHELL}\"" end end end |
- (Integer) length
Entries in Env var.
390 391 392 |
# File 'bin/rumodule', line 390 def length @value.length end |
- (Object) prepend_path(value)
Place new value infront of the path.
350 351 352 353 354 |
# File 'bin/rumodule', line 350 def prepend_path( value ) @dirty = true @unset = false @value.unshift( value ) end |
- (Object) remove_path(value)
Remove value from the path.
370 371 372 373 374 |
# File 'bin/rumodule', line 370 def remove_path( value ) @dirty = true @unset = false @value.delete( value ) end |
- (Object) set(value)
Set variable to a value.
332 333 334 335 336 |
# File 'bin/rumodule', line 332 def set( value ) @dirty = true @unset = false @value = [ value ] end |
- (Object) unset
Unset variable from env.
340 341 342 343 344 |
# File 'bin/rumodule', line 340 def unset @dirty = true @unset = true @value = [] end |