Class: R10K::Util::Subprocess Private
- Inherits:
-
Object
- Object
- R10K::Util::Subprocess
- Includes:
- Logging
- Defined in:
- lib/r10k/util/subprocess.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
The subprocess namespace implements an interface similar to childprocess. The interface has been simplified to make it easier to use and does not depend on native code.
Defined Under Namespace
Modules: POSIX, Windows Classes: IO, Result, Runner, SubprocessError
Constant Summary
Constants included from Logging
Instance Attribute Summary collapse
- #argv ⇒ Object readonly private
-
#cwd ⇒ String
The directory to be used as the cwd when executing the command.
- #logger ⇒ Object writeonly private
-
#raise_on_fail ⇒ true, false
Determine whether #execute raises an error when the command exits with a non-zero exit status.
Class Method Summary collapse
-
.runner ⇒ Class < R10K::Util::Subprocess::Runner]
private
Class < R10K::Util::Subprocess::Runner].
Instance Method Summary collapse
-
#execute ⇒ R10K::Util::Subprocess::Result
Execute the given command and return the result of evaluation.
-
#initialize(argv) ⇒ Subprocess
constructor
private
Prepare the subprocess invocation.
Methods included from Logging
formatter, included, level, level=, levels, #logger, #logger_name, outputter, parse_level
Constructor Details
#initialize(argv) ⇒ Subprocess
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Prepare the subprocess invocation.
55 56 57 58 59 |
# File 'lib/r10k/util/subprocess.rb', line 55 def initialize(argv) @argv = argv @raise_on_fail = false end |
Instance Attribute Details
#argv ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
34 35 36 |
# File 'lib/r10k/util/subprocess.rb', line 34 def argv @argv end |
#cwd ⇒ String
Returns The directory to be used as the cwd when executing the command.
45 46 47 |
# File 'lib/r10k/util/subprocess.rb', line 45 def cwd @cwd end |
#logger=(value) ⇒ Object (writeonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
50 51 52 |
# File 'lib/r10k/util/subprocess.rb', line 50 def logger=(value) @logger = value end |
#raise_on_fail ⇒ true, false
Determine whether #execute raises an error when the command exits with a non-zero exit status.
40 41 42 |
# File 'lib/r10k/util/subprocess.rb', line 40 def raise_on_fail @raise_on_fail end |
Class Method Details
.runner ⇒ Class < R10K::Util::Subprocess::Runner]
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns Class < R10K::Util::Subprocess::Runner].
22 23 24 25 26 27 28 |
# File 'lib/r10k/util/subprocess.rb', line 22 def self.runner if R10K::Util::Platform.windows? R10K::Util::Subprocess::Windows::Runner else R10K::Util::Subprocess::POSIX::Runner end end |
Instance Method Details
#execute ⇒ R10K::Util::Subprocess::Result
Execute the given command and return the result of evaluation.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/r10k/util/subprocess.rb', line 67 def execute subprocess = self.class.runner.new(@argv) subprocess.cwd = @cwd if @cwd logmsg = "Starting process: #{@argv.inspect}" logmsg << "(cwd: #{@cwd})" if @cwd logger.debug2(logmsg) result = subprocess.run logger.debug2("Finished process:\n#{result.format}") if @raise_on_fail and subprocess.crashed? raise SubprocessError.new("Command exited with non-zero exit code", :result => result) end result end |