Class: Antex::Command

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(name:, sources:, targets:, command_line:) ⇒ Command

Note:

A command with no targets will always skip since it needs to produce nothing!

Initializes the command.

Parameters:

  • name (String)

    name of the command (just for error reporting)

  • sources (Array)

    list of source files

  • targets (Array)

    list of target files

  • command_line (String)

    command line that will be executed



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

#statusProcess::Status? (readonly)

Returns the status returned by the command line.

Returns:

  • (Process::Status, nil)

    the status returned by the command line



30
31
32
# File 'lib/antex/command.rb', line 30

def status
  @status
end

#stderrString? (readonly)

Returns the stderr returned by the command line.

Returns:

  • (String, nil)

    the stderr returned by the command line



27
28
29
# File 'lib/antex/command.rb', line 27

def stderr
  @stderr
end

#stdoutString? (readonly)

Returns the stdout returned by the command line.

Returns:

  • (String, nil)

    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.

Raises:



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