Class: Bcome::Command::Local
- Inherits:
-
Object
- Object
- Bcome::Command::Local
- Defined in:
- lib/objects/command/local.rb
Instance Attribute Summary collapse
-
#process_status ⇒ Object
readonly
Returns the value of attribute process_status.
-
#stderr ⇒ Object
readonly
Returns the value of attribute stderr.
-
#stdout ⇒ Object
readonly
Returns the value of attribute stdout.
Class Method Summary collapse
Instance Method Summary collapse
- #exit_code ⇒ Object
- #failed? ⇒ Boolean
-
#initialize(command, success_exit_codes = [0]) ⇒ Local
constructor
A new instance of Local.
- #is_success? ⇒ Boolean
- #pretty_result ⇒ Object
- #syscall ⇒ Object
Constructor Details
#initialize(command, success_exit_codes = [0]) ⇒ Local
Returns a new instance of Local.
15 16 17 18 |
# File 'lib/objects/command/local.rb', line 15 def initialize(command, success_exit_codes = [0]) @command = command @success_exit_codes = success_exit_codes end |
Instance Attribute Details
#process_status ⇒ Object (readonly)
Returns the value of attribute process_status.
13 14 15 |
# File 'lib/objects/command/local.rb', line 13 def process_status @process_status end |
#stderr ⇒ Object (readonly)
Returns the value of attribute stderr.
13 14 15 |
# File 'lib/objects/command/local.rb', line 13 def stderr @stderr end |
#stdout ⇒ Object (readonly)
Returns the value of attribute stdout.
13 14 15 |
# File 'lib/objects/command/local.rb', line 13 def stdout @stdout end |
Class Method Details
.run(raw_command, _success_exit_codes = [0]) ⇒ Object
7 8 9 10 11 |
# File 'lib/objects/command/local.rb', line 7 def self.run(raw_command, _success_exit_codes = [0]) command = new(raw_command) command.syscall command end |
Instance Method Details
#exit_code ⇒ Object
26 27 28 |
# File 'lib/objects/command/local.rb', line 26 def exit_code @process_status ? @process_status.exitstatus : 1 end |
#failed? ⇒ Boolean
34 35 36 |
# File 'lib/objects/command/local.rb', line 34 def failed? !is_success? end |
#is_success? ⇒ Boolean
30 31 32 |
# File 'lib/objects/command/local.rb', line 30 def is_success? @success_exit_codes.include?(exit_code) end |
#pretty_result ⇒ Object
38 39 40 |
# File 'lib/objects/command/local.rb', line 38 def pretty_result is_success? ? "success / exit code: #{exit_code}".success : "failure / exit code: #{exit_code}".error end |
#syscall ⇒ Object
20 21 22 23 24 |
# File 'lib/objects/command/local.rb', line 20 def syscall @stdout, @stderr, @process_status = Open3.capture3(@command) rescue Exception => e @stderr = e. end |