Class: Command::Runner::Message
- Inherits:
-
Object
- Object
- Command::Runner::Message
- Defined in:
- lib/command/runner/message.rb
Overview
This contains information about the process that was run, such as its exit code, process id, and even time it took to run.
Instance Attribute Summary collapse
-
#exit_code ⇒ Numeric
readonly
The code the process exited with.
-
#line ⇒ String
readonly
The exact line that was executed.
-
#options ⇒ Hash
readonly
The options that the user passed when executing the process.
-
#process_id ⇒ Numeric
readonly
The process id the process ran under.
-
#status ⇒ Process::Status
readonly
The status of the process.
-
#stderr ⇒ String
readonly
The standard error of the process that was executed.
-
#stdout ⇒ String
readonly
The standard out of the process that was executed.
-
#time ⇒ Numeric
readonly
The amount of time the process took to run, in seconds.
Class Method Summary collapse
-
.error(line) ⇒ Object
For when a message is created for a NoCommandError.
Instance Method Summary collapse
-
#executed? ⇒ Boolean
Whether or not the process was actually executed.
-
#initialize(data) ⇒ Message
constructor
Initialize the message with the given data about the process.
-
#no_command? ⇒ Boolean
Whether or not the command existed; or, if the exit code is 127.
-
#nonzero_exit? ⇒ Boolean
Whether or not the exit code was non-zero.
-
#successful? ⇒ Boolean
Returns if the command was successful or not.
Constructor Details
#initialize(data) ⇒ Message
Initialize the message with the given data about the process.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/command/runner/message.rb', line 39 def initialize(data) { :executed => false, :time => 0, :process_id => -1, :exit_code => 0, :env => {}, :options => {}, :stdout => "\n", :stderr => "", :line => "", :status => nil }.merge(data).each do |k, v| instance_variable_set(:"@#{k}", (v.dup rescue v)) end end |
Instance Attribute Details
#exit_code ⇒ Numeric (readonly)
The code the process exited with.
118 119 120 121 |
# File 'lib/command/runner/message.rb', line 118 [:exit_code, :process_id, :time, :stdout, :stderr, :options, :line, :status].each do |key| define_method(key) { instance_variable_get(:"@#{key}") } end |
#line ⇒ String (readonly)
The exact line that was executed.
118 119 120 121 |
# File 'lib/command/runner/message.rb', line 118 [:exit_code, :process_id, :time, :stdout, :stderr, :options, :line, :status].each do |key| define_method(key) { instance_variable_get(:"@#{key}") } end |
#options ⇒ Hash (readonly)
The options that the user passed when executing the process.
118 119 120 121 |
# File 'lib/command/runner/message.rb', line 118 [:exit_code, :process_id, :time, :stdout, :stderr, :options, :line, :status].each do |key| define_method(key) { instance_variable_get(:"@#{key}") } end |
#process_id ⇒ Numeric (readonly)
The process id the process ran under.
118 119 120 121 |
# File 'lib/command/runner/message.rb', line 118 [:exit_code, :process_id, :time, :stdout, :stderr, :options, :line, :status].each do |key| define_method(key) { instance_variable_get(:"@#{key}") } end |
#status ⇒ Process::Status (readonly)
The status of the process.
118 119 120 121 |
# File 'lib/command/runner/message.rb', line 118 [:exit_code, :process_id, :time, :stdout, :stderr, :options, :line, :status].each do |key| define_method(key) { instance_variable_get(:"@#{key}") } end |
#stderr ⇒ String (readonly)
The standard error of the process that was executed.
118 119 120 121 |
# File 'lib/command/runner/message.rb', line 118 [:exit_code, :process_id, :time, :stdout, :stderr, :options, :line, :status].each do |key| define_method(key) { instance_variable_get(:"@#{key}") } end |
#stdout ⇒ String (readonly)
The standard out of the process that was executed.
118 119 120 121 |
# File 'lib/command/runner/message.rb', line 118 [:exit_code, :process_id, :time, :stdout, :stderr, :options, :line, :status].each do |key| define_method(key) { instance_variable_get(:"@#{key}") } end |
#time ⇒ Numeric (readonly)
The amount of time the process took to run, in seconds.
118 119 120 121 |
# File 'lib/command/runner/message.rb', line 118 [:exit_code, :process_id, :time, :stdout, :stderr, :options, :line, :status].each do |key| define_method(key) { instance_variable_get(:"@#{key}") } end |
Class Method Details
.error(line) ⇒ Object
For when a message is created for a NoCommandError.
@ return [Message]
13 14 15 |
# File 'lib/command/runner/message.rb', line 13 def self.error(line) new(:line => line, :exit_code => 127) end |
Instance Method Details
#executed? ⇒ Boolean
Whether or not the process was actually executed.
59 60 61 |
# File 'lib/command/runner/message.rb', line 59 def executed? @executed end |
#no_command? ⇒ Boolean
Whether or not the command existed; or, if the exit code is 127.
82 83 84 |
# File 'lib/command/runner/message.rb', line 82 def no_command? exit_code == 127 end |
#nonzero_exit? ⇒ Boolean
Whether or not the exit code was non-zero.
66 67 68 |
# File 'lib/command/runner/message.rb', line 66 def nonzero_exit? exit_code != 0 end |
#successful? ⇒ Boolean
Returns if the command was successful or not. Success is defined as an exit code of 0.
74 75 76 |
# File 'lib/command/runner/message.rb', line 74 def successful? exit_code == 0 end |