Class: RVM::Shell::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/rvm/shell/result.rb

Overview

Represents the output of a shell command. This includes the exit status (and the helpful #successful? method) as well accessors for the command and stdout / stderr.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command, status, stdout, stderr) ⇒ Result

Creates a new result object with the given details.



11
12
13
14
15
16
17
18
# File 'lib/rvm/shell/result.rb', line 11

def initialize(command, status, stdout, stderr)
  @command     = command.dup.freeze
  @raw_status  = status
  @environment = (@raw_status ? (@raw_status["environment"] || {}) : {})
  @successful  = (exit_status == 0)
  @stdout      = stdout.freeze
  @stderr      = stderr.freeze
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



8
9
10
# File 'lib/rvm/shell/result.rb', line 8

def command
  @command
end

#raw_statusObject (readonly)

Returns the value of attribute raw_status.



8
9
10
# File 'lib/rvm/shell/result.rb', line 8

def raw_status
  @raw_status
end

#stderrObject (readonly)

Returns the value of attribute stderr.



8
9
10
# File 'lib/rvm/shell/result.rb', line 8

def stderr
  @stderr
end

#stdoutObject (readonly)

Returns the value of attribute stdout.



8
9
10
# File 'lib/rvm/shell/result.rb', line 8

def stdout
  @stdout
end

Instance Method Details

#[](key) ⇒ Object

Returns a value from the outputs environment.



31
32
33
# File 'lib/rvm/shell/result.rb', line 31

def [](key)
  env[key.to_s]
end

#envObject

Returns the hash of the environment.



21
22
23
# File 'lib/rvm/shell/result.rb', line 21

def env
  @environment
end

#exit_statusObject

Returns the exit status for the program



36
37
38
# File 'lib/rvm/shell/result.rb', line 36

def exit_status
  @exit_status ||= (Integer(@raw_status["exit_status"]) rescue 1)
end

#successful?Boolean

Whether or not the command had a successful exit status.

Returns:

  • (Boolean)


26
27
28
# File 'lib/rvm/shell/result.rb', line 26

def successful?
  @successful
end