Class: ShellHelpers::ProcessStatus

Inherits:
Object
  • Object
show all
Defined in:
lib/shell_helpers/run.rb

Overview

ProcessStatus {{{ from methadone (process_status.rb; last import v1.3.1-2-g9be3b5a)

A wrapper/enhancement of Process::Status that handles coercion and expected nonzero statuses

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status, expected = nil) ⇒ ProcessStatus

Create the ProcessStatus with the given status. respond to success?,exitstatus,status

status:: if this responds to #exitstatus, that method is used to extract the exit code. If it's an Int, that is used as the exit code. Otherwise, it's truthiness is used: 0 for truthy, 1 for falsey. expected:: an Int or Array of Int representing the expected exit status, other than zero, that represent "success". Ex usage: stdout,stderr,status = DR::Run.run_command(command,*opts) process_status = DR::ProcessStatus.new(status,expected)



225
226
227
228
229
# File 'lib/shell_helpers/run.rb', line 225

def initialize(status,expected=nil)
	@status=status
	@exitstatus = derive_exitstatus(status)
	@success = ([0] + Array(expected)).include?(@exitstatus)
end

Instance Attribute Details

#exitstatusObject (readonly)

The exit status, either directly from a Process::Status, from the exit code, or derived from a non-Int value.



216
217
218
# File 'lib/shell_helpers/run.rb', line 216

def exitstatus
  @exitstatus
end

#statusObject (readonly)

The exit status, either directly from a Process::Status, from the exit code, or derived from a non-Int value.



216
217
218
# File 'lib/shell_helpers/run.rb', line 216

def status
  @status
end

Instance Method Details

#success?Boolean

True if the exit status was a successul (i.e. expected) one.

Returns:

  • (Boolean)


232
233
234
# File 'lib/shell_helpers/run.rb', line 232

def success?
	@success
end