Class: Antex::Command
- Inherits:
-
Object
- Object
- Antex::Command
- Defined in:
- lib/antex/command.rb
Overview
This class encapsulates the execution of a command line that needs some source files to produce some target files.
Existence checks are performed on files:
-
if all targets exist before execution then it is skipped
-
all sources must exist before execution
-
all targets must exist after execution
Details of the execution itself are given by the attributes #stdout, #stderr and #status.
Defined Under Namespace
Classes: ExecutionFailed, MissingSourceFiles, MissingTargetFiles
Instance Attribute Summary collapse
-
#status ⇒ Process::Status?
readonly
The
statusreturned by the command line. -
#stderr ⇒ String?
readonly
The
stderrreturned by the command line. -
#stdout ⇒ String?
readonly
The
stdoutreturned by the command line.
Instance Method Summary collapse
-
#initialize(name:, sources:, targets:, command_line:) ⇒ Command
constructor
Initializes the command.
-
#run! ⇒ Object
Executes the command.
Constructor Details
#initialize(name:, sources:, targets:, command_line:) ⇒ Command
A command with no targets will always skip since it needs to produce nothing!
Initializes the command.
41 42 43 44 45 46 |
# File 'lib/antex/command.rb', line 41 def initialize(name:, sources:, targets:, command_line:) @name = name @sources = sources @targets = targets @command_line = command_line end |
Instance Attribute Details
#status ⇒ Process::Status? (readonly)
Returns the status returned by the command line.
30 31 32 |
# File 'lib/antex/command.rb', line 30 def status @status end |
#stderr ⇒ String? (readonly)
Returns the stderr returned by the command line.
27 28 29 |
# File 'lib/antex/command.rb', line 27 def stderr @stderr end |
#stdout ⇒ String? (readonly)
Returns the stdout returned by the command line.
24 25 26 |
# File 'lib/antex/command.rb', line 24 def stdout @stdout end |
Instance Method Details
#run! ⇒ Object
Executes the command.
53 54 55 56 57 58 59 60 |
# File 'lib/antex/command.rb', line 53 def run! return if all_exist? @targets check_source_files! @stdout, @stderr, @status = Open3.capture3 @command_line check_status! check_target_files! end |