Class: NliPipeline::SystemWrapper::CallWrapper
- Inherits:
-
Object
- Object
- NliPipeline::SystemWrapper::CallWrapper
- Includes:
- AbstractUtil
- Defined in:
- lib/nli_pipeline/system_wrapper/call_wrapper.rb
Overview
wrapper for system calls handles output / debugging
Direct Known Subclasses
Instance Attribute Summary collapse
-
#last_return_code ⇒ Object
Returns the value of attribute last_return_code.
Class Method Summary collapse
-
.required_args ⇒ Array
no required args in this case, but method is required.
-
.supported_args ⇒ Hash
static methods required by NliPipeline::AbstractUtil::init_attrs.
Instance Method Summary collapse
- #call_system(command, custom_error_message: false, return_output: false) ⇒ String | Boolean
-
#initialize(**kwargs) ⇒ CallWrapper
constructor
A new instance of CallWrapper.
Methods included from AbstractUtil
#add_attrs, #drop_forbidden_args_message, included, #init_with_attrs, #raise_unless_all, #to_s
Constructor Details
#initialize(**kwargs) ⇒ CallWrapper
Returns a new instance of CallWrapper.
32 33 34 |
# File 'lib/nli_pipeline/system_wrapper/call_wrapper.rb', line 32 def initialize(**kwargs) init_with_attrs(**kwargs) end |
Instance Attribute Details
#last_return_code ⇒ Object
Returns the value of attribute last_return_code.
13 14 15 |
# File 'lib/nli_pipeline/system_wrapper/call_wrapper.rb', line 13 def last_return_code @last_return_code end |
Class Method Details
.required_args ⇒ Array
no required args in this case, but method is required
27 28 29 |
# File 'lib/nli_pipeline/system_wrapper/call_wrapper.rb', line 27 def self.required_args [] end |
.supported_args ⇒ Hash
static methods required by NliPipeline::AbstractUtil::init_attrs
19 20 21 |
# File 'lib/nli_pipeline/system_wrapper/call_wrapper.rb', line 19 def self.supported_args { debug: false, fail_on_error: false } end |
Instance Method Details
#call_system(command, custom_error_message: false, return_output: false) ⇒ String | Boolean
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/nli_pipeline/system_wrapper/call_wrapper.rb', line 40 def call_system(command, custom_error_message: false, return_output: false) result = return_output ? `#{command}`.chomp : system(command) return_code = $CHILD_STATUS if @debug puts("\t#{command}") puts("\treturned: #{result} #{return_code}") end # can't return both output and code in return_output case # so assign instance var @last_return_code = return_code # only catches cases where command finished but with non-zero exit code # e.g. "echo 'hi" will throw an exception regardless of @fail_on_error # "echo 'hi' grep | 'y'" will throw a CallWrapperError only if @fail_on_error is true if @fail_on_error && !result puts(.red) if raise CallWrapperError.new(call: command, code: return_code) end result end |