CommandExecutionCapture
This code defines a Ruby module named `Sublayer` containing a nested module `Actions`. Within the `Actions` module, there is a class `RunTestCommandAction` that inherits from a base class (`Base`). The primary purpose of `RunTestCommandAction` is to execute an external command passed during its initialization and capture its output. It takes a single initial argument, `test_command`, which represents the command to be executed. The instance method `call` executes the given command using Ruby's `Open3.capture3` method, capturing the standard output (`stdout`), standard error (`stderr`), and the exit status (`status`). These three values are then returned as a tuple. This setup can be useful for automating and handling the execution of shell commands or scripts from within a Ruby application, particularly focusing on capturing the output and exit status for further processing or logging.
module Sublayer
module Actions
class RunTestCommandAction < Base
def initialize(test_command:)
@test_command = test_command
end
def call
stdout, stderr, status = Open3.capture3(@test_command)
[stdout, stderr, status]
end
end
end
end