Class: Metasploit::Yard::Aruba::RvmEnv::Prepend

Inherits:
Export show all
Defined in:
lib/metasploit/yard/aruba/rvm_env/prepend.rb

Overview

Recognizes exports that are actually prepending values to the pre-existing value as is the case with PATH.

Constant Summary collapse

REGEXP =

Matches line with format export <name>=<quote><value>$<name><quote>. <value> will contain trailing File::PATH_SEPARATOR, so it can be directly prepended to the current value of <name> to get the value to set the environment variable.

/\Aexport (?<name>\S+?)(\s+;\s+\k<name>)?=(?<quote>"|')(?<value>.*?#{File::PATH_SEPARATOR})\$\k<name>\k<quote>\Z/

Instance Attribute Summary

Attributes inherited from Export

#value

Attributes inherited from Variable

#name

Instance Method Summary collapse

Methods inherited from Export

#==, #initialize, parse

Methods inherited from Variable

#==, #initialize

Constructor Details

This class inherits a constructor from Metasploit::Yard::Aruba::RvmEnv::Export

Instance Method Details

#change(options = {}) ⇒ Object

Parameters:

  • options (Hash{Symbol => Object}) (defaults to: {})

Options Hash (options):



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/metasploit/yard/aruba/rvm_env/prepend.rb', line 18

def change(options={})
  options.assert_valid_keys(:from, :world)

  from = options.fetch(:from)
  world = options.fetch(:world)

  from_directories = from.value.split(File::PATH_SEPARATOR)
  to_directories = value.split(File::PATH_SEPARATOR)

  path = ENV[name]

  to_directories.zip(from_directories) do |to_directory, from_directory|
    path = path.gsub(from_directory, to_directory)
  end

  world.set_env(name, path)
end