Class: Metasploit::Yard::Aruba::RvmEnv::Export

Inherits:
Variable
  • Object
show all
Defined in:
lib/metasploit/yard/aruba/rvm_env/export.rb

Overview

Recognizes exports of a variable

Direct Known Subclasses

Prepend

Constant Summary collapse

REGEXP =

Matches line with format export <name>=<quote><value><quote>

/\Aexport (?<name>\S+?)(\s+;\s+\k<name>)?=(?<quote>"|')(?<value>.*?)\k<quote>\Z/

Instance Attribute Summary collapse

Attributes inherited from Variable

#name

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ Export

Returns a new instance of Export.

Parameters:

  • attributes (Hash{Symbol=>String}) (defaults to: {})

Options Hash (attributes):

  • :name (String) — default: see Metasploit::Yard::Aruba::RvmEnv::Variable#name}
  • :value (String) — default: see #value


48
49
50
51
52
53
# File 'lib/metasploit/yard/aruba/rvm_env/export.rb', line 48

def initialize(attributes={})
  attributes.assert_valid_keys(:name, :value)

  super(name: attributes[:name])
  @value = attributes[:value]
end

Instance Attribute Details

#valueString

The value to which Variable#name should be set

Returns:

  • (String)


18
19
20
# File 'lib/metasploit/yard/aruba/rvm_env/export.rb', line 18

def value
  @value
end

Class Method Details

.parse(line) ⇒ Export?

Parses line of rvm env output into an Metasploit::Yard::Aruba::RvmEnv::Export if it matches REGEXP.

Parameters:

  • line (String)

    a line of rvm env output

Returns:

  • (Export)

    if line contains export.

  • (nil)

    otherwise



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/metasploit/yard/aruba/rvm_env/export.rb', line 29

def self.parse(line)
  # use self:: so subclasses can override
  match = self::REGEXP.match(line)

  if match
    new(
        name: match[:name],
        value: match[:value]
    )
  end
end

Instance Method Details

#==(other) ⇒ true, false

Whether this export is the same class and has the same #value as other.

Returns:

  • (true)

    if other.class is Metasploit::Yard::Aruba::RvmEnv::Export and other.value is #value.

  • (false)

    otherwise



59
60
61
# File 'lib/metasploit/yard/aruba/rvm_env/export.rb', line 59

def ==(other)
  super(other) && other.value == self.value
end

#change(options = {}) ⇒ Object

Parameters:

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

Options Hash (options):



68
69
70
71
72
73
74
# File 'lib/metasploit/yard/aruba/rvm_env/export.rb', line 68

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

  world = options.fetch(:world)

  world.set_env(name, value)
end